brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · 337be78 Raw
56 lines · plain
1.. title:: clang-tidy - concurrency-mt-unsafe2 3concurrency-mt-unsafe4=====================5 6Checks for some thread-unsafe functions against a black list of7known-to-be-unsafe functions. Usually they access static variables without8synchronization (e.g. gmtime(3)) or utilize signals in a racy way.9The set of functions to check is specified with the `FunctionSet` option.10 11Note that using some thread-unsafe functions may be still valid in12concurrent programming if only a single thread is used (e.g. setenv(3)),13however, some functions may track a state in global variables which14would be clobbered by subsequent (non-parallel, but concurrent) calls to15a related function. E.g. the following code suffers from unprotected16accesses to a global state:17 18.. code-block:: c++19 20    // getnetent(3) maintains global state with DB connection, etc.21    // If a concurrent green thread calls getnetent(3), the global state is corrupted.22    netent = getnetent();23    yield();24    netent = getnetent();25 26 27Examples:28 29.. code-block:: c++30 31    tm = gmtime(timep); // uses a global buffer32 33    sleep(1); // implementation may use SIGALRM34 35Options36-------37 38.. option:: FunctionSet39 40  Specifies which functions in libc should be considered thread-safe,41  possible values are `posix`, `glibc`, or `any`.42 43  `posix` means POSIX defined thread-unsafe functions. POSIX.1-200144  in "2.9.1 Thread-Safety" defines that all functions specified in the45  standard are thread-safe except a predefined list of thread-unsafe46  functions.47 48  Glibc defines some of them as thread-safe (e.g. dirname(3)), but adds49  non-POSIX thread-unsafe ones (e.g. getopt_long(3)). Glibc's list is50  compiled from GNU web documentation with a search for MT-Safe tag:51  https://www.gnu.org/software/libc/manual/html_node/POSIX-Safety-Concepts.html52 53  If you want to identify thread-unsafe API for at least one libc or54  unsure which libc will be used, use `any` (default).55 56