thr_setconcurrency(3thread) thr_setconcurrency(3thread)
NAME
thr_setconcurrency - request a level of concurrency
SYNOPSIS
cc [options] -Kthread file
#include <thread.h>
int thr_setconcurrency(int new_level);
Parameters
new_level the requested level of concurrency
DESCRIPTION
thr_setconcurrency tells the implementation the number of
lightweight processes (LWPs) that the user would like
available for running multiplexed threads.
thr_setconcurrency sets to new_level the requested level, or
degree, of concurrency, which is the number of LWPs that the
user would like available to execute multiplexed threads in
the process. The requested concurrency is a hint to the
implementation as to the level of concurrency expected by the
user; the implementation may use this value to affect the
number of LWPs available for running multiplexed threads.
Note that thr_create(3thread) with the THR_INCR_CONC flag
provides more deterministic control over concurrency.
new_level Parameter
new_level must be a non-negative integer. thr_setconcurrency
interprets it as follows:
If new_level is zero, thr_setconcurrency sets the level
of concurrency to the default level.
If new_level is greater than the current number of LWPs,
in this implementation, thr_setconcurrency will create
LWPs until the number of LWPs in the pool equals
new_level, unless new_level exceeds a system limit. In
that case, LWPs will be created only up to the system
limit. However, if new_level exceeds the number of
threads in the process, thr_setconcurrency will create
new LWPs so that the number of LWPs equals the number of
threads in the process.
If new_level is less than the current number of LWPs,
thr_setconcurrency will allow LWPs to terminate
themselves as the result of aging (see below).
Copyright 1994 Novell, Inc. Page 1
thr_setconcurrency(3thread) thr_setconcurrency(3thread)
If new_level is equal to the current number of LWPs,
thr_setconcurrency sets the new level of concurrency,
but does not create or terminate any LWPs.
When the number of LWPs becomes greater than the number of
threads in the process, the concurrency level may
automatically decay over time to be equal to or less than the
number of threads in the process. This process is called
aging. In this implementation, if an LWP is inactive for a
certain length of time, it will terminate itself if:
the number of LWPs is greater than the requested
concurrency level
or the number of LWPs is greater than the number of
threads in the process
Notes
The creation or termination of LWPs is not necessarily
synchronous with the call to thr_setconcurrency, therefore an
error may not be returned. For example, if new_level exceeds
a system limit, EAGAIN may not be returned, and any LWPs
created asynchronously as a result of the call will not be
terminated.
The Threads Library will always ensure that an LWP is
available to run multiplexed threads.
Return Values
thr_setconcurrency returns zero for success and an error
number for failure, as described below.
Errors
If any of the following conditions is detected,
thr_setconcurrency returns the corresponding value:
EINVAL new_level is negative
EAGAIN A system resource limit would have been exceeded by
using the requested value in the implementation's
concurrency algorithm. LWPs created up to the failed
_lwp_create will not be killed but will continue to
exist. Because the change of concurrency level is
not necessarily synchronous with the call to
thr_setconcurrency, this condition is not always
detected.
Copyright 1994 Novell, Inc. Page 2
thr_setconcurrency(3thread) thr_setconcurrency(3thread)
USAGE
The Threads Library ensures that a sufficient number of
threads are active so that the process can continue to make
progress. While this conserves system resources, it may not
produce the most effective level of concurrency.
thr_setconcurrency permits the application to give the Threads
Library a hint about the desired level of concurrency.
REFERENCES
thr_create(3thread), thr_getconcurrency(3thread),
thread(3thread)
Copyright 1994 Novell, Inc. Page 3