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 |
A local variable is used as an argument for a thread.
| クラス名 | Local Variable Passed to Thread | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| 日本語クラス名 | Local Variable Passed to Thread | |||||||||
| クラス分類 | 信頼性 (reliability) | |||||||||
| ニーモニック | CONCURRENCY.LOCALARG | |||||||||
| カテゴリー |
|
|||||||||
| 対応言語 | C および C++ で利用可能です。 |
|||||||||
| 有効/無効設定 | このワーニングクラスのチェックはデフォルトで有効になっています。チェックを無効にするにはプロジェクト設定ファイル
(configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += discard class="Local Variable Passed to Thread" |
#include <pthread.h>
#define NUM_THREADS 5
void *perform_work(void *arguments){
/* do something with arguments */
return NULL;
}
int main(void) {
pthread_t threads[2*NUM_THREADS];
int local_thread_args[NUM_THREADS]; /* automatic storage duration */
static int static_thread_args[NUM_THREADS]; /* static storage duration */
int i;
int result_code;
/* pass local data to some threads */
for (i = 0; i < NUM_THREADS; i++) {
local_thread_args[i] = i;
result_code = pthread_create(&threads[2*i], NULL, perform_work, &local_thread_args[i]); /* 'Local Variable Passed to Thread' warning issued here */
if (result_code != 0) {return result_code;}
}
/* pass local-static data to some threads */
for (i = 0; i < NUM_THREADS; i++) {
static_thread_args[i] = i;
result_code = pthread_create(&threads[2*i+1], NULL, perform_work, &static_thread_args[i]); /* ok: static_thread_args has static storage duration */
if (result_code != 0) {return result_code;}
}
/* wait for threads to complete */
for (i = 0; i < 2*NUM_THREADS; i++) {
result_code = pthread_join(threads[i], NULL);
if (result_code != 0) {return result_code;}
}
return 0;
}
CodeSonar ships with library models that allow it to a number of functions that pass arguments to threads, across many different libraries. If one of these functions is passed a local variable, 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 Local Variable Passed to Thread warnings.
| Functions that can trigger warnings include... | |
|---|---|
| Apache Portable Runtime (APR) | apr_thread_create() |
| ARINC 653 | CREATE_PROCESS() |
| CMX-RTX | K_Task_Create() |
| FreeRTOS | xTaskCreate() |
| libc | g_thread_create() |
| Linux Kernel | kernel_thread() |
| Mac OS X | kernel_thread_start() |
| Win32/MFC | AfxBeginThread() |
| Netscape Portable Runtime (NSPR) | PR_CreateThread() |
| Qt | QThread::start() |
| ThreadX | tx_thread_create() |
| uC/OS-III | OSTaskCreate() |
| VxWorks | taskInit() |
| Win32 | CreateThread() |
| wxWidgets | wxThread::Create() |
設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。