ORIGINAL
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
original::thread Class Referencefinal

High-level thread wrapper. More...

#include <thread.h>

Inheritance diagram for original::thread:
Inheritance graph
Collaboration diagram for original::thread:
Collaboration graph

Public Member Functions

 thread ()
 Construct empty thread.
 
template<typename Callback , typename... ARGS>
 thread (Callback c, ARGS &&... args)
 Construct and start thread with callback (AUTO_JOIN policy)
 
template<typename Callback , typename... ARGS>
 thread (Callback c, joinPolicy policy, ARGS &&... args)
 Construct and start a thread with the given callback and join policy.
 
 thread (const thread &)=delete
 Deleted copy constructor.
 
threadoperator= (const thread &)=delete
 Deleted copy assignment.
 
 thread (thread &&other) noexcept
 Move constructor (defaults to AUTO_JOIN)
 
 thread (thread &&other, joinPolicy policy) noexcept
 Move constructor with specified join policy.
 
threadoperator= (thread &&other) noexcept
 Move assignment.
 
ul_integer id () const override
 Get thread identifier.
 
bool joinable () const override
 Check if thread is joinable.
 
integer compareTo (const thread &other) const override
 
u_integer toHash () const noexcept override
 Computes the hash of the object.
 
std::string className () const override
 Gets the class name for type identification.
 
void join () override
 Wait for thread to complete.
 
void detach () override
 Detach thread (allow it to run independently)
 
 ~thread () override
 Destructor.
 
- Public Member Functions inherited from original::threadBase< thread >
 threadBase () noexcept=default
 Default constructor.
 
 threadBase (const threadBase &)=delete
 Deleted copy constructor.
 
 threadBase (threadBase &&other) noexcept=default
 Default move constructor.
 
 ~threadBase () noexcept override=default
 Destructor.
 
threadBaseoperator= (const threadBase &)=delete
 Deleted copy assignment.
 
threadBaseoperator= (threadBase &&other) noexcept=default
 Default move assignment.
 
 operator bool () const
 Check if thread is valid.
 
bool operator! () const
 Check if thread is not valid.
 
std::string className () const override
 Gets the class name for type identification.
 
std::string toString (bool enter) const override
 Generates formatted string representation.
 
- Public Member Functions inherited from original::comparable< DERIVED >
virtual integer compareTo (const DERIVED &other) const =0
 Compares the current object with another of the same type.
 
bool operator== (const DERIVED &other) const
 Checks if the current object is equal to another.
 
bool operator!= (const DERIVED &other) const
 Checks if the current object is not equal to another.
 
bool operator< (const DERIVED &other) const
 Checks if the current object is less than another.
 
bool operator> (const DERIVED &other) const
 Checks if the current object is greater than another.
 
bool operator<= (const DERIVED &other) const
 Checks if the current object is less than or equal to another.
 
bool operator>= (const DERIVED &other) const
 Checks if the current object is greater than or equal to another.
 
virtual ~comparable ()=default
 Virtual destructor for proper cleanup of derived objects.
 
- Public Member Functions inherited from original::hashable< DERIVED >
virtual bool equals (const DERIVED &other) const noexcept
 Compares two objects for equality.
 
virtual ~hashable ()=0
 Virtual destructor.
 
- Public Member Functions inherited from original::printable
 operator std::string () const
 Explicit conversion to std::string.
 
 operator const char * () const
 Explicit conversion to C-style string.
 
const chartoCString (bool enter) const
 Direct C-string access with formatting control.
 
template<typename TYPE >
auto formatString (const TYPE &t) -> std::string
 
template<typename TYPE >
auto formatCString (const TYPE &t) -> const char *
 
template<typename TYPE >
auto formatEnum (const TYPE &t) -> std::string
 
template<typename TYPE >
auto formatString (TYPE *const &ptr) -> std::string
 

Static Public Member Functions

static ul_integer thisId ()
 
static void sleep (const time::duration &d)
 Puts the current thread to sleep for a specified duration.
 
- Static Public Member Functions inherited from original::printable
template<typename TYPE >
static std::string formatString (const TYPE &t)
 Universal value-to-string conversion with type-specific formatting.
 
template<Printable TYPE>
static std::string formatString (const TYPE &t)
 Specialization for types deriving from printable.
 
template<EnumType TYPE>
static std::string formatString (const TYPE &t)
 Specialization for enum types with type-safe formatting.
 
template<typename TYPE >
static std::string formatString (TYPE *const &ptr)
 Pointer-specific formatting with null safety.
 
template<typename TYPE >
static const charformatCString (const TYPE &t)
 C-string cache for temporary usage with static storage.
 
template<typename TYPE >
static std::string formatEnum (const TYPE &t)
 Enum formatting utility with underlying value extraction.
 
template<>
auto formatString (const char &t) -> std::string
 
template<>
auto formatString (const bool &t) -> std::string
 
template<>
auto formatString (const char *const &ptr) -> std::string
 

Static Public Attributes

static constexpr auto AUTO_JOIN = joinPolicy::AUTO_JOIN
 Alias for joinPolicy::AUTO_JOIN.
 
static constexpr auto AUTO_DETACH = joinPolicy::AUTO_DETACH
 Alias for joinPolicy::AUTO_DETACH.
 

Additional Inherited Members

Detailed Description

High-level thread wrapper.

Manages thread lifetime with automatic join/detach. Provides RAII semantics for thread management with configurable join policy. Implements threadBase interface while wrapping a pThread instance.

Key Features:

Join Policy:

Example usage:

// thread work
Unique ownership smart pointer with move semantics.
Definition ownerPtr.h:37
High-level thread wrapper.
Definition thread.h:307
static constexpr auto AUTO_DETACH
Alias for joinPolicy::AUTO_DETACH.
Definition thread.h:353
See also
original::pThread
original::threadBase
original::thread::joinPolicy

Constructor & Destructor Documentation

◆ thread() [1/5]

original::thread::thread ( )
inlineexplicit

Construct empty thread.

Postcondition
Creates an invalid thread object (not associated with any execution)

◆ thread() [2/5]

template<typename Callback , typename ... ARGS>
original::thread::thread ( Callback  c,
ARGS &&...  args 
)
explicit

Construct and start thread with callback (AUTO_JOIN policy)

Template Parameters
CallbackCallable type
ARGSArgument types
Parameters
cCallable to execute in thread
argsArguments forwarded to the callable
Postcondition
Thread starts and will be joined on destruction

◆ thread() [3/5]

template<typename Callback , typename ... ARGS>
original::thread::thread ( Callback  c,
joinPolicy  policy,
ARGS &&...  args 
)
explicit

Construct and start a thread with the given callback and join policy.

Template Parameters
CallbackType of the callable object
ARGSTypes of arguments to pass to the callable
Parameters
cCallable object to run in the new thread
policyJoin policy (AUTO_JOIN or AUTO_DETACH)
argsArguments forwarded to the callable
Postcondition
Starts a new thread and applies the specified join policy
See also
joinPolicy

◆ thread() [4/5]

original::thread::thread ( thread &&  other)
inlinenoexcept

Move constructor (defaults to AUTO_JOIN)

Parameters
otherThread to move from
Postcondition
Ownership transferred; will join on destruction

◆ thread() [5/5]

original::thread::thread ( thread &&  other,
joinPolicy  policy 
)
inlinenoexcept

Move constructor with specified join policy.

Parameters
otherThread to move from
policyJoin policy (AUTO_JOIN or AUTO_DETACH)
Postcondition
Ownership transferred and join behavior follows policy

◆ ~thread()

original::thread::~thread ( )
inlineoverride

Destructor.

Note
Automatically joins or detaches based on will_join policy
Terminates program if join/detach operation fails

Member Function Documentation

◆ className()

std::string original::thread::className ( ) const
inlineoverridevirtual

Gets the class name for type identification.

Returns
Class name as string.

Override in derived classes to provide accurate type names.

class MyClass : public printable {
std::string className() const override { return "MyClass"; }
};
Base class providing polymorphic string conversion capabilities.
Definition printable.h:39

Reimplemented from original::printable.

◆ detach()

void original::thread::detach ( )
inlineoverridevirtual

Detach thread (allow it to run independently)

Note
Terminates program if detach fails
After detach, the thread object no longer represents the thread

Implements original::threadBase< thread >.

◆ id()

original::ul_integer original::thread::id ( ) const
inlineoverridevirtual

Get thread identifier.

Returns
Unique identifier for the thread

Implements original::threadBase< thread >.

◆ join()

void original::thread::join ( )
inlineoverridevirtual

Wait for thread to complete.

Note
Terminates program if join fails
Blocks until the thread completes execution

Implements original::threadBase< thread >.

◆ joinable()

bool original::thread::joinable ( ) const
inlineoverridevirtual

Check if thread is joinable.

Returns
true if thread is joinable
Note
Implementation of threadBase::joinable()

Implements original::threadBase< thread >.

◆ operator=()

original::thread & original::thread::operator= ( thread &&  other)
inlinenoexcept

Move assignment.

Parameters
otherThread to move from
Returns
Reference to this object
Postcondition
Ownership and join policy transferred

◆ sleep()

void original::thread::sleep ( const time::duration d)
inlinestatic

Puts the current thread to sleep for a specified duration.

Parameters
dDuration to sleep
Note
This is a platform-independent sleep function:
  • On GCC/Linux uses clock_nanosleep with CLOCK_REALTIME
  • On Windows uses Sleep() with millisecond precision
  • Handles EINTR interruptions automatically
  • Negative durations result in no sleep
Exceptions
sysErrorif sleep operation fails (except on Windows)

◆ toHash()

original::u_integer original::thread::toHash ( ) const
inlineoverridevirtualnoexcept

Computes the hash of the object.

Returns
A hash value

Default implementation uses byte-wise hashing of object representation. Override for custom hashing logic.

Reimplemented from original::hashable< DERIVED >.

Member Data Documentation

◆ AUTO_DETACH

original::thread::AUTO_DETACH = joinPolicy::AUTO_DETACH
staticconstexpr

Alias for joinPolicy::AUTO_DETACH.

The thread is detached in the destructor (non-blocking cleanup).

◆ AUTO_JOIN

original::thread::AUTO_JOIN = joinPolicy::AUTO_JOIN
staticconstexpr

Alias for joinPolicy::AUTO_JOIN.

The thread is joined in the destructor (blocking cleanup).


The documentation for this class was generated from the following file: