[#BloombergLP-bslmt-ThreadUtil-create-0e78]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bslmt.adoc[bslmt]::xref:BloombergLP/bslmt/ThreadUtil.adoc[ThreadUtil]::create
:relfileprefix: ../../../
:mrdocs:

`create` overloads

== Synopses

Declared in `&lt;bslmt&lowbar;threadutil&period;h&gt;`

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&period; Optionally specify `attributes` describing the properties for the new thread&period; If `attributes` is not supplied, a default `ThreadAttributes` object is used&period; Use the global allocator to supply memory&period; Return 0 on success, and a non&hyphen;zero value otherwise&period; `function` shall be a reference to a type, `INVOKABLE`, that can be copy&hyphen;constructed, and where the expression `(void)function()` will execute a function call (i&period;e&period;, either a `void()()` function, or a functor object implementing `void operator()()`)&period; `bslmt&colon;&colon;Configuration` is used to determine the created thread&apos;s default stack&hyphen;size if either `attributes` is not supplied or if `attributes&period;stackSize()` has the unset value&period; The behavior is undefined unless `attributes`, if specified, has a `stackSize` that is either greater than 0 or `e&lowbar;UNSET&lowbar;STACK&lowbar;SIZE`&period; Note that unless the created thread is explicitly &quot;detached&quot; (by invoking the `detach` class method with `handle`) or the `k&lowbar;CREATE&lowbar;DETACHED` attribute is specified, a call to `join` must be made to reclaim any system resources associated with the newly&hyphen;created thread&period; Also note that users are encouraged to either explicitly provide a stack size attribute, or configure a `bslmt`&hyphen;wide default using `bslmt&colon;&colon;Configuration`, because the default stack size is surprisingly small on some platforms&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class INVOKABLE&gt;
static
int
xref:BloombergLP/bslmt/ThreadUtil/create-041.adoc[create](
    xref:BloombergLP/bslmt/ThreadUtil/Handle.adoc[Handle]* handle,
    INVOKABLE const& function);
----

[.small]#xref:BloombergLP/bslmt/ThreadUtil/create-041.adoc[_» more&period;&period;&period;_]#

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&period; Optionally specify `attributes` describing the properties for the new thread&period; If `attributes` is not supplied, a default `ThreadAttributes` object is used&period; Use the global allocator to supply memory&period; Return 0 on success, and a non&hyphen;zero value otherwise&period; `bslmt&colon;&colon;Configuration` is used to determine the created thread&apos;s default stack&hyphen;size if either `attributes` is not supplied or if `attributes&period;stackSize()` has the unset value&period; The behavior is undefined unless `attributes`, if specified, has a `stackSize` that is either greater than 0 or `e&lowbar;UNSET&lowbar;STACK&lowbar;SIZE`&period; Note that unless the created thread is explicitly &quot;detached&quot; (by invoking the `detach` class method with `handle`) or the `k&lowbar;CREATE&lowbar;DETACHED` attribute is specified, a call to `join` must be made to reclaim any system resources associated with the newly&hyphen;created thread&period; Also note that users are encouraged to either explicitly provide a stack size attribute, or configure a `bslmt`&hyphen;wide default using `bslmt&colon;&colon;Configuration`, because the default stack size is surprisingly small on some platforms&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
static
int
xref:BloombergLP/bslmt/ThreadUtil/create-0e7c.adoc[create](
    xref:BloombergLP/bslmt/ThreadUtil/Handle.adoc[Handle]* handle,
    xref:BloombergLP/bslmt/ThreadUtil/ThreadFunction.adoc[ThreadFunction] function,
    void* userData);
----

[.small]#xref:BloombergLP/bslmt/ThreadUtil/create-0e7c.adoc[_» more&period;&period;&period;_]#

Same as the preceding overload, with the specified `attributes`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class INVOKABLE&gt;
static
int
xref:BloombergLP/bslmt/ThreadUtil/create-047.adoc[create](
    xref:BloombergLP/bslmt/ThreadUtil/Handle.adoc[Handle]* handle,
    xref:BloombergLP/bslmt/ThreadAttributes.adoc[ThreadAttributes] const& attributes,
    INVOKABLE const& function);
----

[.small]#xref:BloombergLP/bslmt/ThreadUtil/create-047.adoc[_» more&period;&period;&period;_]#

Same as the preceding overload, using the specified `attributes`&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
static
int
xref:BloombergLP/bslmt/ThreadUtil/create-0d.adoc[create](
    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);
----

[.small]#xref:BloombergLP/bslmt/ThreadUtil/create-0d.adoc[_» more&period;&period;&period;_]#


[.small]#Created with https://www.mrdocs.com[MrDocs]#
