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.2p0 | CONFIDENTIAL | CodeSecure Inc |
A program performs a thread creation operation outside the initialization phase.
For the purpose of this check, a thread creation operation is considered to be in the initialization phase if it takes place in a function f() specified with configuration file parameter THREAD_INIT_FUNCTIONS, or in a function directly or transitively called by f().
| Class Name | Dynamic Thread Creation | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Significance | style | ||||||||||||
| Mnemonic | CONCURRENCY.DTC | ||||||||||||
| Categories |
|
||||||||||||
| Availability | Available for C and C++. |
||||||||||||
| Enabling | Checks for this warning class are
disabled by default. To enable them, add the following WARNING_FILTER
rule to the project configuration file.
WARNING_FILTER += allow class="Dynamic Thread Creation" |
#include <pthread.h>
pthread_t thread1;
pthread_t thread2;
void * thread_func( void * arg ) { return arg; }
/* With factory settings, function name 'dyn_init' matches a
* THREAD_INIT_FUNCTIONS rule, so this function can directly or
* transitively call thread creation functions without triggering a
* 'Dynamic Thread Creation' warning
*/
void dyn_init(void){
if( pthread_create( &thread1, NULL, thread_func, NULL ) ) { thread1 = 0; }
if( pthread_create( &thread2, NULL, thread_func, NULL ) ) { thread2 = 0; }
}
int main(int argc, char *argv[]){
pthread_t thrd;
/* starting process - do all thread creation now */
dyn_init();
/* no more thread creation from this point on */
/* ... */
if( !pthread_create( &thrd, NULL, thread_func, NULL ) ) /* 'Dynamic Thread Creation' warning issued here */
pthread_detach( thrd );
/* ... */
if( thread1 ) pthread_detach( thread1 );
if( thread2 ) pthread_detach( thread2 );
return 0;
}
Warnings of this class can be triggered by any function specified with configuration file parameter THREAD_CREATION_FUNCTIONS.
Only code reachable from a program entry point can trigger warnings for this class. CodeSonar will treat a function as a program entry point if it is specified with configuration file parameter PROGRAM_ENTRY_POINTS. The factory setting of this parameter instructs CodeSonar to treat main() and init() as entry points.
The following configuration file parameters affect checks for this warning class.
To report problems with this documentation, please visit https://support.codesecure.com/.