File: ThreadingSupportAPI.rst

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 1,998,492 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (67 lines) | stat: -rw-r--r-- 2,685 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
=====================
Threading Support API
=====================

.. contents::
   :local:

Overview
========

Libc++ supports using multiple different threading models and configurations
to implement the threading parts of libc++, including ``<thread>`` and ``<mutex>``.
These different models provide entirely different interfaces from each
other. To address this libc++ wraps the underlying threading API in a new and
consistent API, which it uses internally to implement threading primitives.

The ``<__thread/support.h>`` header is where libc++ defines its internal
threading interface. It documents the functions and declarations required
to fullfil the internal threading interface.

External Threading API and the ``<__external_threading>`` header
================================================================

In order to support vendors with custom threading API's libc++ allows the
entire internal threading interface to be provided by an external,
vendor provided, header.

When ``_LIBCPP_HAS_THREAD_API_EXTERNAL`` is defined the ``<__thread/support.h>``
header simply forwards to the ``<__external_threading>`` header (which must exist).
It is expected that the ``<__external_threading>`` header provide the exact
interface normally provided by ``<__thread/support.h>``.

External Threading Library
==========================

libc++ can be compiled with its internal threading API delegating to an external
library. Such a configuration is useful for library vendors who wish to
distribute a thread-agnostic libc++ library, where the users of the library are
expected to provide the implementation of the libc++ internal threading API.

On a production setting, this would be achieved through a custom
``<__external_threading>`` header, which declares the libc++ internal threading
API but leaves out the implementation.

Threading Configuration Macros
==============================

**_LIBCPP_HAS_NO_THREADS**
  This macro is defined when libc++ is built without threading support. It
  should not be manually defined by the user.

**_LIBCPP_HAS_THREAD_API_EXTERNAL**
  This macro is defined when libc++ should use the ``<__external_threading>``
  header to provide the internal threading API. This macro overrides
  ``_LIBCPP_HAS_THREAD_API_PTHREAD``.

**_LIBCPP_HAS_THREAD_API_PTHREAD**
  This macro is defined when libc++ should use POSIX threads to implement the
  internal threading API.

**_LIBCPP_HAS_THREAD_API_C11**
  This macro is defined when libc++ should use C11 threads to implement the
  internal threading API.

**_LIBCPP_HAS_THREAD_API_WIN32**
  This macro is defined when libc++ should use Win32 threads to implement the
  internal threading API.