Manual Reference Pages - LIBTHR (3)
- 1:1 POSIX threads library
Interaction With Run-time Linker
library provides a 1:1 implementation of the
library interfaces for application threading.
has been optimized for use by applications expecting system scope thread
semantics, and can provide significant performance improvements
.Lb libkse .
The library is tightly integrated with the run-time link editor
.Lb libc ;
all three components must be built from the same source tree.
libraries from different versions of
is not supported.
The run-time linker
has some code to ensure backward-compatibility with older versions of
The man page documents the quirks and tunables of the
When linking with
the run-time dependency
is recorded in the produced object.
A locked mutex (see
is represented by a volatile variable of type
which records the global system identifier of the thread
owning the lock.
performs a contested mutex acquisition in three stages, each of which
is more resource-consuming than the previous.
The first two stages are only applied for a mutex of
First, on SMP systems, a spin loop
is performed, where the library attempts to acquire the lock by
The loop count is controlled by the
environment variable, with a default value of 2000.
If the spin loop
was unable to acquire the mutex, a yield loop
is executed, performing the same
acquisition attempts as the spin loop,
but each attempt is followed by a yield of the CPU time
of the thread using the
By default, the yield loop
is not executed.
This is controlled by the
If both the spin and yield loops
failed to acquire the lock, the thread is taken off the CPU and
put to sleep in the kernel with the
The kernel wakes up a thread and hands the ownership of the lock to
the woken thread when the lock becomes available.
Each thread is provided with a private user-mode stack area
used by the C runtime.
The size of the main (initial) thread stack is set by the kernel, and is
controlled by the
process resource limit (see
By default, the main threads stack size is equal to the value of
for the process.
environment variable is present in the process environment
(its value does not matter),
the main threads stack is reduced to 4MB on 64bit architectures, and to
2MB on 32bit architectures, when the threading library is initialized.
The rest of the address space area which has been reserved by the
kernel for the initial process stack is used for non-initial thread stacks
in this case.
The presence of the
environment variable overrides
it is kept for backward-compatibility.
The size of stacks for threads created by the process at run-time
call is controlled by thread attributes: see
in particular, the
If no attributes for the thread stack size are specified, the default
non-initial thread stack size is 2MB for 64bit architectures, and 1MB
for 32bit architectures.
The following environment variables are recognized by
and adjust the operation of the library at run-time:
Disables the reduction of the initial thread stack enabled by
Causes a reduction of the initial thread stack, as described in the
This was the default behaviour of
.Fx 11.0 .
The integer value of the variable overrides the default count of
iterations in the
of the mutex acquisition.
The default count is 2000, set by the
constant in the
A non-zero integer value enables the yield loop
in the process of the mutex acquisition.
The value is the count of loop operations.
The integer value of the variable specifies how often blocked
threads are inserted at the head of the sleep queue, instead of its tail.
Bigger values reduce the frequency of the FIFO discipline.
The value must be between 0 and 255.
INTERACTION WITH RUN-TIME LINKER
installs interposing handlers into the hooks exported by
The interposers provide real locking implementation instead of the
stubs for single-threaded processes in
cancellation support and some modifications to the signal operations.
cannot be unloaded; the
function does not perform any action when called with a handle for
One of the reasons is that the internal interposing of
functions cannot be undone.
The implementation interposes the user-installed
This interposing is done to postpone signal delivery to threads which
entered (libthr-internal) critical sections, where the calling
of the user-provided signal handler is unsafe.
An example of such a situation is owning the internal library lock.
When a signal is delivered while the signal handler cannot be safely
called, the call is postponed and performed until after the exit from
the critical section.
This should be taken into account when interpreting
was originally created by
.An Jeff Roberson Aq jeff@FreeBSD.org ,
and enhanced by
.An Jonathan Mini Aq mini@FreeBSD.org
.An Mike Makonnen Aq mtm@FreeBSD.org .
It has been substantially rewritten and optimized by
.An David Xu Aq davidxu@FreeBSD.org .
Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.