PTHREAD...URRENCY(3POSIX)
π PTHREAD...URRENCY π (3POSIX)
okay bestie, welcome to the POSIX Programmer's Manual π«Ά this one's pthread_getconcurrency and pthread_setconcurrency, and it's giving β¨concurrency controlβ¨ but like... as a hint. let's get into it.
πΈ PROLOG πΈ
so like, heads up: this manual page is part of the POSIX Programmer's Manual. the Linux implementation of this interface may differ (so go check the corresponding Linux manual page for the tea on Linux behavior), or honestly the interface may not even be implemented on Linux at all. π
β¨ NAME β¨
pthread_getconcurrency, pthread_setconcurrency β get and set the level of concurrency π
π¦ SYNOPSIS π¦
#include <pthread.h>
int pthread_getconcurrency(void);
int pthread_setconcurrency(int new_level);
π DESCRIPTION π
so. unbound threads in a process may or may not be required to be simultaneously active β it's a vibe, not a guarantee. by default, the threads implementation makes sure a sufficient number of threads are active so that the process can continue to make progress. and like, that conserves system resources, which is great and all, but lowkey it may not produce the most effective level of concurrency. π
the pthread_setconcurrency() function lets an application inform the threads implementation of its desired concurrency level, new_level. the actual level of concurrency the implementation gives you as a result of this call? unspecified. so don't come for it, bestie.
if new_level is zero, it causes the implementation to maintain the concurrency level at its discretion as if pthread_setconcurrency() had never been called. ghosted, basically. π»
the pthread_getconcurrency() function shall return the value set by a previous call to the pthread_setconcurrency() function. and if pthread_setconcurrency() was not previously called, this function shall return zero to indicate that the implementation is maintaining the concurrency level.
a call to pthread_setconcurrency() shall inform the implementation of its desired concurrency level. and the implementation shall use this as a hint, not a requirement. it's giving "suggestion box, not a contract" π
if an implementation does not support multiplexing of user threads on top of several kernel-scheduled entities, the pthread_setconcurrency() and pthread_getconcurrency() functions are provided for source code compatibility but they shall have no effect when called. but to maintain the function semantics, the new_level parameter is saved when pthread_setconcurrency() is called, so that a subsequent call to pthread_getconcurrency() shall return the same value. it's just holding onto it for you, no cap. π
π RETURN VALUE π
if successful, the pthread_setconcurrency() function shall return zero; otherwise, an error number shall be returned to indicate the error.
the pthread_getconcurrency() function shall always return the concurrency level set by a previous call to pthread_setconcurrency(). and if pthread_setconcurrency() has never been called, pthread_getconcurrency() shall return zero.
π ERRORS π
the pthread_setconcurrency() function shall fail if:
EINVALβ the value specified bynew_levelis negative. (negative?? girl. no. π ββοΈ)EAGAINβ the value specified bynew_levelwould cause a system resource to be exceeded.
the pthread_setconcurrency() function shall not return an error code of [EINTR].
the following sections are informative. (iykyk β informative means it's the bonus lore, not the rulebook.)
π EXAMPLES π
None.
like, literally none. nothing. the void. π
πΈ APPLICATION USAGE πΈ
app developers, listen up: an implementation can always ignore any calls to pthread_setconcurrency() and just return a constant for pthread_getconcurrency(). and for this exact reason, it is not recommended that portable applications use this function. bestie, if you want portability, walk away. πΆββοΈ
π§ RATIONALE π§
None.
again, nothing. iconic minimalism honestly. β¨
π₯ FUTURE DIRECTIONS π₯
These functions may be removed in a future version. so like... they might get cancelled. π«£
π SEE ALSO π
the Base Definitions volume of POSIX.1β2017, <pthread.h>
π COPYRIGHT π
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page, bestie!! π
this one came to you from IEEE/The Open Group, 2017 β yeah, the 2017 edition, vintage but still slaying β under the manual name PTHREAD...URRENCY(3POSIX). go forth and hint at your concurrency levels responsibly π«Άβ¨
π¦ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 Β· Other
- debian trixie: manpages-posix-dev 2017a-2 Β· Other
- ubuntu jammy: manpages-posix-dev 2017a-2 Β· Other
- ubuntu noble: manpages-posix-dev 2017a-2 Β· Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms