Skip to content

Commit 196dca7

Browse files
authored
[clang][analyzer][NFC] Improve docs of alpha.unix.BlockInCriticalSection (#93812)
- Enhanced descriptions for blocking and critical section functions - Added an additional code sample highlighting interleaved C and C++ style mutexes
1 parent a65771f commit 196dca7

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

clang/docs/analyzer/checkers.rst

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3135,17 +3135,26 @@ alpha.unix
31353135
alpha.unix.BlockInCriticalSection (C)
31363136
"""""""""""""""""""""""""""""""""""""
31373137
Check for calls to blocking functions inside a critical section.
3138-
Applies to: ``lock, unlock, sleep, getc, fgets, read, recv, pthread_mutex_lock,``
3139-
`` pthread_mutex_unlock, mtx_lock, mtx_timedlock, mtx_trylock, mtx_unlock, lock_guard, unique_lock``
3138+
Blocking functions detected by this checker: ``sleep, getc, fgets, read, recv``.
3139+
Critical section handling functions modelled by this checker: ``lock, unlock, pthread_mutex_lock, pthread_mutex_trylock, pthread_mutex_unlock, mtx_lock, mtx_timedlock, mtx_trylock, mtx_unlock, lock_guard, unique_lock``.
31403140
31413141
.. code-block:: c
31423142
3143-
void test() {
3144-
std::mutex m;
3145-
m.lock();
3146-
sleep(3); // warn: a blocking function sleep is called inside a critical
3147-
// section
3148-
m.unlock();
3143+
void pthread_lock_example(pthread_mutex_t *m) {
3144+
pthread_mutex_lock(m); // note: entering critical section here
3145+
sleep(10); // warn: Call to blocking function 'sleep' inside of critical section
3146+
pthread_mutex_unlock(m);
3147+
}
3148+
3149+
.. code-block:: cpp
3150+
3151+
void overlapping_critical_sections(mtx_t *m1, std::mutex &m2) {
3152+
std::lock_guard lg{m2}; // note: entering critical section here
3153+
mtx_lock(m1); // note: entering critical section here
3154+
sleep(10); // warn: Call to blocking function 'sleep' inside of critical section
3155+
mtx_unlock(m1);
3156+
sleep(10); // warn: Call to blocking function 'sleep' inside of critical section
3157+
// still inside of the critical section of the std::lock_guard
31493158
}
31503159
31513160
.. _alpha-unix-Chroot:

0 commit comments

Comments
 (0)