|
BDE 4.39.x Production Release
|
#include <bslmt_threadutil.h>
This struct provides a suite of portable utility functions for managing threads.
See bslmt_threadutil
Public Types | |
| typedef ThreadUtilImpl< Platform::ThreadPolicy > | Imp |
| typedef Imp::Handle | Handle |
| typedef Imp::NativeHandle | NativeHandle |
| typedef Imp::Id | Id |
| typedef bslmt_ThreadFunction | ThreadFunction |
| typedef Imp::Key | Key |
| typedef bslmt_KeyDestructorFunction | Destructor |
Static Public Member Functions | |
| static bool | isThreadLimitReached () |
| 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) |
| static void | sleepUntil (const bsls::TimeInterval &absoluteTime, bsls::SystemClockType::Enum clockType=bsls::SystemClockType::e_REALTIME) |
| 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 bsls::Types::Uint64 | selfKernelIdAsUint64 () |
| 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 () |
| static void | setThreadLimit (unsigned int n) |
Prototype for thread-specific key destructors.
| typedef Imp::Handle bslmt::ThreadUtil::Handle |
Thread handle type. Use this type to refer to a thread in a platform-independent way.
| typedef Imp::Id bslmt::ThreadUtil::Id |
Thread identifier type - distinguished from a Handle in that it does not have any resources associated with it, whereas Handle may, depending on platform.
| typedef ThreadUtilImpl<Platform::ThreadPolicy> bslmt::ThreadUtil::Imp |
Platform-specific implementation type.
| typedef Imp::Key bslmt::ThreadUtil::Key |
Thread-specific key type, used to refer to thread-specific storage.
| typedef Imp::NativeHandle bslmt::ThreadUtil::NativeHandle |
Platform-specific thread handle type.
Prototype for thread entry-point functions.
Return true if the specified a and b thread handles identify the same thread, or if both a and b are invalid handles, and false otherwise.
a or b is an invalid handle, but not both, this method returns false. Return true if the specified a thread identifier is associated with the same thread as the specified b thread identifier, and false otherwise.
|
static |
Return an integer scheduling priority appropriate for the specified normalizedSchedulingPriority and the specified policy. If either the minimum or maximum priority for this platform cannot be determined, return ThreadAttributes::e_UNSET_PRIORITY. Higher values of normalizedSchedulingPriority are considered to represent more urgent priorities.
policy is a valid ThreadAttributes::SchedulingPolicy and normalizedSchedulingPriority is in the range [ 0.0, 1.0 ].
|
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.
attributes, if specified, has a stackSize that is either greater than 0 or e_UNSET_STACK_SIZE. 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.
|
inlinestatic |
|
static |
|
inlinestatic |
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.
attributes, if specified, has a stackSize that is either greater than 0 or e_UNSET_STACK_SIZE. 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.
|
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.
|
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.
attributes, if specified, has a stackSize that is either greater than 0 or e_UNSET_STACK_SIZE. 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.
|
inlinestatic |
|
static |
|
static |
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.
attributes, if specified, has a stackSize that is either greater than 0 or e_UNSET_STACK_SIZE. 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.
|
inlinestatic |
Delete the specified key from the calling process, and disassociate all threads from the thread key cleanup function supplied when key was created (see createKey). Return 0 on success, and a non-zero value otherwise.
key was obtained from a successful call to createKey and has not already been deleted.
|
inlinestatic |
"Detach" the thread identified by the specified handle such that when it terminates, the resources associated with that thread will automatically be reclaimed.
handle was obtained by a call to create or self. join the thread to retrieve its exit status.
|
inlinestatic |
Exit the current thread and return the specified status. If the current thread is not "detached", then a call to join must be made to reclaim any resources used by the thread, and to retrieve the exit status.
|
inlinestatic |
Return the maximum available priority for the specified policy, where policy is of type ThreadAttributes::SchedulingPolicy. Return ThreadAttributes::e_UNSET_PRIORITY if the maximum scheduling priority cannot be determined.
getMinSchedulingPriority(policy) and getMaxSchedulingPriority(policy) return the same value.
|
inlinestatic |
Return the minimum available priority for the specified policy, where policy is of type ThreadAttributes::SchedulingPolicy. Return ThreadAttributes::e_UNSET_PRIORITY if the minimum scheduling priority cannot be determined.
getMinSchedulingPriority(policy) and getMaxSchedulingPriority(policy) return the same value.
|
inlinestatic |
Return the thread-local value associated with the specified key. A key is shared among all threads and the value associated with key for each thread is 0 until it is set by that thread using setSpecific.
createKey, key was obtained from a successful call to createKey, and key has not been deleted.
|
inlinestatic |
Load the name of the current thread into the specified *threadName.
*threadName on platforms other than Linux, Solaris, Darwin, and Windows.
|
inlinestatic |
Return the unique identifier of the thread having the specified threadHandle within the current process.
handle was obtained by a call to create or self.
|
inlinestatic |
Return a hint at the number of concurrent threads supported by this platform on success, and 0 otherwise.
|
inlinestatic |
Return the unique integral identifier of a thread uniquely identified by the specified threadId within the current process.
DEPRECATED: use idAsUint64.
|
inlinestatic |
Return the unique integral identifier of a thread uniquely identified by the specified threadId within the current process.
|
inlinestatic |
Return a reference to the non-modifiable Handle object that is guaranteed never to be a valid thread handle.
Return true if the specified a and b thread handles identify the same thread, or if both a and b are invalid handles, and false otherwise.
a or b is an invalid handle, but not both, this method returns false.DEPRECATED: use areEqual instead.
Return true if the specified lhs thread identifier is associated with the same thread as the specified rhs thread identifier, and false otherwise.
DEPRECATED: use areEqualId instead.
|
static |
Counts down the limit counter set by ThreadUtil::setThreadLimit. Returns true if current thread creation attempt should be failed.
setThreadLimit.
|
inlinestatic |
Suspend execution of the current thread until the thread referred to by the specified threadHandle terminates, and reclaim any system resources associated with threadHandle. Return 0 on success, and a non-zero value otherwise. If the optionally specified status is not 0, load into *status the value returned by the function supplied at the creation of the thread identified by threadHandle.
threadHandle was obtained by a call to create.
|
inlinestatic |
Suspend execution of the current thread for a period of at least the specified microseconds and the optionally specified seconds (relative time), or an interrupting signal is received.
|
inlinestatic |
Return the platform-specific identifier associated with the thread referred to by the specified handle.
handle was obtained by a call to create or self. selfIdAsUint).
|
inlinestatic |
Return an opaque thread identifier that can be used to refer to the current thread in calls to other ThreadUtil methods.
|
inlinestatic |
Return an identifier that can be used to uniquely identify the current thread within the current process.
|
inlinestatic |
Return an integral identifier that can be used to uniquely identify the current thread within the current process.
DEPRECATED: use selfIdAsUint64 instead.
|
inlinestatic |
Return an integral identifier that can be used to uniquely identify the current thread within the current process.
|
inlinestatic |
Return an integral identifier that can be used to uniquely identify the kernel thread within the current process.
selfIdAsUint64(). Also note that this value is valid only until the thread terminates, and may be reused thereafter. Also note that this method returns the kernel thread id only on the operating systems which implement that (on Windows, the thread ids returned by both methods are the same).
|
inlinestatic |
Associate the specified thread-local value with the specified process-wide key. Return 0 on success, and a non-zero value otherwise. The value associated with a thread for a given key is 0 until it has been set by that thread using setSpecific.
createKey, key was obtained from a successful call to createKey, and key has not been deleted.
|
static |
Enable a thread creation limit. If set to non-zero value n'th thread creation will fail. The limit is disabled by setting the limit to 0. Only intended to be used in tests to inject thread creation errors.
|
inlinestatic |
Set the name of the current thread to the specified threadName. On platforms other than Linux, Solaris, Darwin and Windows this method has no effect.
threadName will be truncated to a length of 15 bytes, not including the terminating '\0'.
|
inlinestatic |
Suspend execution of the current thread for a period of at least the specified (relative) sleepTime, or an interrupting signal is received.
|
inlinestatic |
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).
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).
|
inlinestatic |
Move the current thread to the end of the scheduler's queue and schedule another thread to run.