@@ -3135,17 +3135,26 @@ alpha.unix
3135
3135
alpha.unix .BlockInCriticalSection (C)
3136
3136
"""""""""""""""""""""""""""""""""""""
3137
3137
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 ``.
3140
3140
3141
3141
.. code-block :: c
3142
3142
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
3149
3158
}
3150
3159
3151
3160
.. _alpha-unix-Chroot :
0 commit comments