[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: notation for documenting multithread-safety - clang's warnings
From: |
Bruno Haible |
Subject: |
Re: notation for documenting multithread-safety - clang's warnings |
Date: |
Sun, 01 Dec 2019 08:37:52 +0100 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-166-generic; KDE/5.18.0; x86_64; ; ) |
Ben Pfaff wrote:
> The compiler analyzes the code and reports violations of the
> annotations where possible.
>
> Details:
> https://clang.llvm.org/docs/ThreadSafetyAnalysis.html
>
> The Clang docs mostly talk about C++ but it also supports C.
Indeed, this is a very nice feature. Find attached a test case, where
the compiler warns about locking violations:
$ clang -O -Wthread-safety mt-warnings.c
mt-warnings.c:72:47: warning: reading variable 'account_balance' requires
holding mutex 'account_lock' [-Wthread-safety-analysis]
printf ("Final balance unlocked = %0.2f\n", account_balance);
^
1 warning generated.
To make this easier to use on glibc systems, a couple of annotations in glibc's
<pthread.h> would be needed. Reported as
https://sourceware.org/bugzilla/show_bug.cgi?id=25238
Bruno
mt-warnings.c
Description: Text Data
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: notation for documenting multithread-safety - clang's warnings,
Bruno Haible <=