|
static int | convertToSchedulingPriority (ThreadAttributes::SchedulingPolicy policy, double normalizedSchedulingPriority) |
|
static int | create (Handle *handle, ThreadFunction function, void *userData) |
|
static int | create (Handle *handle, const ThreadAttributes &attributes, ThreadFunction function, void *userData) |
|
template<class INVOKABLE > |
static int | create (Handle *handle, const INVOKABLE &function) |
|
template<class INVOKABLE > |
static int | create (Handle *handle, const ThreadAttributes &attributes, const INVOKABLE &function) |
|
static int | createWithAllocator (Handle *handle, ThreadFunction function, void *userData, bslma::Allocator *allocator) |
|
static int | createWithAllocator (Handle *handle, const ThreadAttributes &attributes, ThreadFunction function, void *userData, bslma::Allocator *allocator) |
|
template<class INVOKABLE > |
static int | createWithAllocator (Handle *handle, const INVOKABLE &function, bslma::Allocator *allocator) |
|
template<class INVOKABLE > |
static int | createWithAllocator (Handle *handle, const ThreadAttributes &attributes, const INVOKABLE &function, bslma::Allocator *allocator) |
|
static int | detach (Handle &handle) |
|
static void | exit (void *status) |
|
static int | getMinSchedulingPriority (ThreadAttributes::SchedulingPolicy policy) |
|
static int | getMaxSchedulingPriority (ThreadAttributes::SchedulingPolicy policy) |
|
static void | getThreadName (bsl::string *threadName) |
|
static int | join (Handle &threadHandle, void **status=0) |
|
static void | microSleep (int microseconds, int seconds=0) |
|
static void | setThreadName (const bslstl::StringRef &threadName) |
|
static void | sleep (const bsls::TimeInterval &sleepTime) |
|
template<class REP_TYPE , class PERIOD_TYPE > |
static void | sleep (const bsl::chrono::duration< REP_TYPE, PERIOD_TYPE > &sleepTime) |
|
static void | sleepUntil (const bsls::TimeInterval &absoluteTime, bsls::SystemClockType::Enum clockType=bsls::SystemClockType::e_REALTIME) |
|
template<class CLOCK , class DURATION > |
static void | sleepUntil (const bsl::chrono::time_point< CLOCK, DURATION > &absoluteTime) |
|
static void | yield () |
|
static bool | areEqual (const Handle &a, const Handle &b) |
|
static bool | areEqualId (const Id &a, const Id &b) |
|
static Id | handleToId (const Handle &threadHandle) |
|
static bsls::Types::Uint64 | idAsUint64 (const Id &threadId) |
|
static int | idAsInt (const Id &threadId) |
|
static const Handle & | invalidHandle () |
|
static bool | isEqual (const Handle &a, const Handle &b) |
|
static bool | isEqualId (const Id &a, const Id &b) |
|
static NativeHandle | nativeHandle (const Handle &handle) |
|
static Handle | self () |
|
static Id | selfId () |
|
static bsls::Types::Uint64 | selfIdAsInt () |
|
static bsls::Types::Uint64 | selfIdAsUint64 () |
|
static int | createKey (Key *key, Destructor threadKeyCleanupFunction) |
|
static int | deleteKey (Key &key) |
|
static void * | getSpecific (const Key &key) |
|
static int | setSpecific (const Key &key, const void *value) |
|
static unsigned int | hardwareConcurrency () |
|
This struct
provides a suite of portable utility functions for managing threads.
template<class INVOKABLE >
int bslmt::ThreadUtil::create |
( |
Handle * |
handle, |
|
|
const INVOKABLE & |
function |
|
) |
| |
|
inlinestatic |
Create a new thread of program control whose entry point will invoke the specified function
object, and load into the specified handle
an identifier that may be used to refer to this thread in calls to other ThreadUtil
methods. Optionally specify attributes
describing the properties for the new thread. If attributes
is not supplied, a default ThreadAttributes
object is used. Use the global allocator to supply memory. Return 0 on success, and a non-zero value otherwise. function
shall be a reference to a type, INVOKABLE
, that can be copy-constructed, and where the expression (void)function()
will execute a function call (i.e., either a void()()
function, or a functor object implementing void operator()()
). bslmt::Configuration
is used to determine the created thread's default stack-size if either attributes
is not supplied or if attributes.stackSize()
has the unset value. The behavior is undefined unless attributes
, if specified, has a stackSize
that is either greater than 0 or e_UNSET_STACK_SIZE
. Note that unless the created thread is explicitly "detached" (by invoking the detach
class method with handle
) or the k_CREATE_DETACHED
attribute is specified, a call to join
must be made to reclaim any system resources associated with the newly-created thread. Also note that users are encouraged to either explicitly provide a stack size attribute, or configure a bslmt
-wide default using bslmt::Configuration
, because the default stack size is surprisingly small on some platforms.
Create a new thread of program control whose entry point will be the specified function
, and which will be passed the specified userData
as its sole argument, and load into the specified handle
an identifier that may be used to refer to this thread in calls to other ThreadUtil
methods. Optionally specify attributes
describing the properties for the new thread. If attributes
is not supplied, a default ThreadAttributes
object is used. Use the global allocator to supply memory. Return 0 on success, and a non-zero value otherwise. bslmt::Configuration
is used to determine the created thread's default stack-size if either attributes
is not supplied or if attributes.stackSize()
has the unset value. The behavior is undefined unless attributes
, if specified, has a stackSize
that is either greater than 0 or e_UNSET_STACK_SIZE
. Note that unless the created thread is explicitly "detached" (by invoking the detach
class method with handle
) or the k_CREATE_DETACHED
attribute is specified, a call to join
must be made to reclaim any system resources associated with the newly-created thread. Also note that users are encouraged to either explicitly provide a stack size attribute, or configure a bslmt
-wide default using bslmt::Configuration
, because the default stack size is surprisingly small on some platforms.
int bslmt::ThreadUtil::createKey |
( |
Key * |
key, |
|
|
Destructor |
threadKeyCleanupFunction |
|
) |
| |
|
inlinestatic |
Load into the specified key
a new process-wide identifier that can be used to store (via setSpecific
) and retrieve (via getSpecific
) a pointer value local to each thread, and associate with the new key the specified threadKeyCleanupFunction
, which will be called by each thread, if threadKeyCleanupFunction
is non-zero and the value associated with key
for that thread is non-zero, with the associated value as an argument, after the function passed to create
has returned and before the thread terminates. Return 0 on success, and a non-zero value otherwise. Note that multiple keys can be defined, which can result in multiple thread key cleanup functions being called for a given thread.
template<class INVOKABLE >
int bslmt::ThreadUtil::createWithAllocator |
( |
Handle * |
handle, |
|
|
const INVOKABLE & |
function, |
|
|
bslma::Allocator * |
allocator |
|
) |
| |
|
inlinestatic |
Create a new thread of program control whose entry point will invoke the specified function
object (using the specified allocator
to supply memory to copy function
), and load into the specified handle
an identifier that may be used to refer to this thread in calls to other ThreadUtil
methods. Optionally specify attributes
describing the properties for the new thread. If attributes
is not supplied, a default ThreadAttributes
object is used. Return 0 on success, and a non-zero value otherwise. function
shall be a reference to a type, INVOKABLE
, that can be copy-constructed, and where the expression (void)function()
will execute a function call (i.e., either a void()()
function, or a functor object implementing void operator()()
). bslmt::Configuration
is used to determine the created thread's default stack-size if either attributes
is not supplied or if attributes.stackSize()
has the unset value. The behavior is undefined unless attributes
, if specified, has a stackSize
that is either greater than 0 or e_UNSET_STACK_SIZE
. Note that unless the created thread is explicitly "detached" (by invoking the detach
class method with handle
) or the k_CREATE_DETACHED
attribute is specified, a call to join
must be made to reclaim any system resources associated with the newly-created thread. Also note that the lifetime of allocator
must exceed the lifetime of the thread. Also note that users are encouraged to either explicitly provide a stack size attribute, or configure a bslmt
-wide default using bslmt::Configuration
, because the default stack size is surprisingly small on some platforms.
Create a new thread of program control whose entry point will be the specified function
, and which will be passed the specified userData
as its sole argument, and load into the specified handle
an identifier that may be used to refer to this thread in calls to other ThreadUtil
methods. Optionally specify attributes
describing the properties for the new thread. If attributes
is not supplied, a default ThreadAttributes
object is used. Use the specified allocator
to supply memory. Return 0 on success, and a non-zero value otherwise. bslmt::Configuration
is used to determine the created thread's default stack-size if either attributes
is not supplied or if attributes.stackSize()
has the unset value. The behavior is undefined unless attributes
, if specified, has a stackSize
that is either greater than 0 or e_UNSET_STACK_SIZE
. Note that unless the created thread is explicitly "detached" (by invoking the detach
class method with handle
) or the k_CREATE_DETACHED
attribute is specified, a call to join
must be made to reclaim any system resources associated with the newly-created thread. Also note that users are encouraged to either explicitly provide a stack size attribute, or configure a bslmt
-wide default using bslmt::Configuration
, because the default stack size is surprisingly small on some platforms.
template<class CLOCK , class DURATION >
void bslmt::ThreadUtil::sleepUntil |
( |
const bsl::chrono::time_point< CLOCK, DURATION > & |
absoluteTime | ) |
|
|
static |
Suspend execution of the current thread until the specified absoluteTime
, which is an absolute time represented as an interval from some epoch, determined by the clock associated with the time point. The behavior is undefined unless absoluteTime
represents a time after January 1, 1970 and before the end of December 31, 9999. Note that the actual time suspended depends on many factors including system scheduling and system timer resolution.
Suspend execution of the current thread until the specified absoluteTime
, or an interrupting signal is received. Optionally specify clockType
which determines the epoch from which the interval absoluteTime
is measured (see {Supported Clock-Types} in the component documentation). The behavior is undefined unless absoluteTime
represents a time after January 1, 1970 and before the end of December 31, 9999 (i.e., a time interval greater than or equal to 0, and less than 253,402,300,800 seconds). Note that the actual time suspended depends on many factors including system scheduling and system timer resolution.