[#BloombergLP-bslmt-ThreadUtil-createWithAllocator-0a] = xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bslmt.adoc[bslmt]::xref:BloombergLP/bslmt/ThreadUtil.adoc[ThreadUtil]::createWithAllocator :relfileprefix: ../../../ :mrdocs: `createWithAllocator` overloads == Synopses Declared in `<bslmt_threadutil.h>` 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. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class INVOKABLE> static int xref:BloombergLP/bslmt/ThreadUtil/createWithAllocator-0d7.adoc[createWithAllocator]( xref:BloombergLP/bslmt/ThreadUtil/Handle.adoc[Handle]* handle, INVOKABLE const& function, xref:BloombergLP/bslma/Allocator.adoc[bslma::Allocator]* allocator); ---- [.small]#xref:BloombergLP/bslmt/ThreadUtil/createWithAllocator-0d7.adoc[_» more..._]# 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. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- static int xref:BloombergLP/bslmt/ThreadUtil/createWithAllocator-0c.adoc[createWithAllocator]( xref:BloombergLP/bslmt/ThreadUtil/Handle.adoc[Handle]* handle, xref:BloombergLP/bslmt/ThreadUtil/ThreadFunction.adoc[ThreadFunction] function, void* userData, xref:BloombergLP/bslma/Allocator.adoc[bslma::Allocator]* allocator); ---- [.small]#xref:BloombergLP/bslmt/ThreadUtil/createWithAllocator-0c.adoc[_» more..._]# Same as the preceding overload, with the specified `attributes`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class INVOKABLE> static int xref:BloombergLP/bslmt/ThreadUtil/createWithAllocator-05.adoc[createWithAllocator]( xref:BloombergLP/bslmt/ThreadUtil/Handle.adoc[Handle]* handle, xref:BloombergLP/bslmt/ThreadAttributes.adoc[ThreadAttributes] const& attributes, INVOKABLE const& function, xref:BloombergLP/bslma/Allocator.adoc[bslma::Allocator]* allocator); ---- [.small]#xref:BloombergLP/bslmt/ThreadUtil/createWithAllocator-05.adoc[_» more..._]# Create a thread with the specified `attributes` and `allocator`. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- static int xref:BloombergLP/bslmt/ThreadUtil/createWithAllocator-0db.adoc[createWithAllocator]( xref:BloombergLP/bslmt/ThreadUtil/Handle.adoc[Handle]* handle, xref:BloombergLP/bslmt/ThreadAttributes.adoc[ThreadAttributes] const& attributes, xref:BloombergLP/bslmt/ThreadUtil/ThreadFunction.adoc[ThreadFunction] function, void* userData, xref:BloombergLP/bslma/Allocator.adoc[bslma::Allocator]* allocator); ---- [.small]#xref:BloombergLP/bslmt/ThreadUtil/createWithAllocator-0db.adoc[_» more..._]# [.small]#Created with https://www.mrdocs.com[MrDocs]#