(initial page) |
(fixed/rewrote grammar) |
||
Line 1: | Line 1: | ||
<small>''This article is about C11 thread support, not [[POSIX Threads]].''</small> | <small>''This article is about C11 thread support, not [[POSIX Threads]].''</small> | ||
− | The [[C programming language]] introduced the semantics necessary for writing a multithreaded program starting with the [[C11]] standard. The standard also specified a set of functions to | + | The [[C programming language]] introduced the semantics necessary for writing a multithreaded program starting with the [[C11]] standard. The standard also specified a set of functions to facilitate inter‐thread communication. These features are provided via the thread library headers which can be utilized by including the [[threads.h - C|<threads.h>]] and [[stdatomic.h - C|<stdatomic.h>]] [[C standard library|standard headers]]. |
== Optional == | == Optional == | ||
Line 24: | Line 24: | ||
[[Category:Stubs]] | [[Category:Stubs]] | ||
[[Category:C programming language]] | [[Category:C programming language]] | ||
+ | [[Category:Concurrency - C]] |
Revision as of 19:29, 17 December 2013
This article is about C11 thread support, not POSIX Threads.
The C programming language introduced the semantics necessary for writing a multithreaded program starting with the C11 standard. The standard also specified a set of functions to facilitate inter‐thread communication. These features are provided via the thread library headers which can be utilized by including the <threads.h> and <stdatomic.h> standard headers.
Optional
Thread support is an optional features for implementations where support for multithreaded programs is possible. The macro __STDC_NO_THREADS__
must be set to 1
if the implementation does not support the <threads.h> header.
#if (__STDC_VERSION__ >= 201112L) && (__STDC_NO_THREADS__ != 1)
/* thread support */
#endif
Creating A Thread
One of the functions included in <threads.h> is thrd_create(),
int thrd_create(thrd_t *thr, thrd_start_t func, void *arg);
Which creates a new thread executing func(arg)
. On a successful operation, the object pointed to by thr
to the identifier of the newly created thread and thrd_success
will be returned. Upon failure thrd_error
or thrd_nomem
will be returned indicating insufficient amount of memory or failure to honor the request.