JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.
If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.
If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.
| CodeSonar® 9.0p0 Hot Tips | CONFIDENTIAL | CodeSecure Inc |
既にロックされているミューテックスに対し、トライロックを試みました。
| クラス名 | Try-lock that will never succeed | ||||||
|---|---|---|---|---|---|---|---|
| 日本語クラス名 | 成功しないトライロック | ||||||
| クラス分類 | 信頼性 (reliability) | ||||||
| ニーモニック | CONCURRENCY.TL | ||||||
| カテゴリー |
|
||||||
| 対応言語 | C および C++ で利用可能です。 |
||||||
| 有効/無効設定 | このワーニングクラスのチェックはデフォルトで有効になっています。チェックを無効にするにはプロジェクト設定ファイル
(configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += discard class="Try-lock that will never succeed" |
#include <pthread.h>
#include <stdlib.h>
void concurrency_tl_bad(void){
pthread_mutex_t mut;
if( pthread_mutex_init( &mut, NULL ) != 0 ) abort();
if( pthread_mutex_lock( &mut ) != 0 ) abort();
if( pthread_mutex_trylock( &mut ) != 0 ) abort(); /* 'Try-lock that will never succeed' warning issued here
* - &mut is already locked by the previous call
* - execution will never reach the following line
*/
if( pthread_mutex_unlock( &mut ) != 0 ) abort();
if( pthread_mutex_destroy( &mut ) != 0 ) abort();
}
void concurrency_tl_ok(void){
pthread_mutex_t mut;
if( pthread_mutex_init( &mut, NULL ) != 0 ) abort();
if( pthread_mutex_trylock( &mut ) != 0 ) abort(); /* ok: &mut is not already locked */
if( pthread_mutex_unlock( &mut ) != 0 ) abort();
if( pthread_mutex_destroy( &mut ) != 0 ) abort();
}
CodeSonar ships with library models that allow it to a number of try-lock functions, across many different libraries. If one of these functions is called when the mutex is always already locked, a warning will be issued.
If you have created a custom library model for some function f() in terms of one of these existing models, calls to f() will also be capable of triggering Try-lock that will never succeed warnings.
| Functions that can trigger warnings include... | |
|---|---|
| Apache Portable Runtime (APR) | apr_global_mutex_trylock() |
| libc | pthread_mutex_trylock() |
| Linux Kernel | down_trylock() |
| Mac OS X | hw_lock_try() |
| OpenMP | omp_test_lock() |
| Qt | QMutex::tryLock() |
| VxWorks | semBCreate() |
| Win32 | TryEnterCriticalSection() |
| wxWidgets | wxMutex::TryLock() |
このワーニングはプログラムの冗長性(もしくは誤解の可能性)を示しています。
設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。