thread_safe_init. NXP CodeWarrior Development Studio
Advertentie
Advertentie
thread_safe_init
This pragma lets you increase the number of nested or recursive class template instantiations allowed. By default, n equals 64; it can be set from 1 to 30000. You should always use the default value unless you receive the error message template too complex or recursive
This pragma does not correspond to any panel setting.
29.42 thread_safe_init
Controls the addition of extra code in the binary to ensure that multiple threads cannot enter a static local initialization at the same time.
Syntax
#pragma thread_safe_init on | off | reset
Remarks
A C++ program that uses multiple threads and static local initializations introduces the possibility of contention over which thread initializes static local variable first. When the pragma is on
, the compiler inserts calls to mutex functions around each static local initialization to avoid this problem. The C++ runtime library provides these mutex functions.
Listing 29-12. Static local initialization example
int func(void) {
// There may be synchronization problems if this function is
// called by multiple threads.
static int countdown = 20;
return countdown--;
}
NOTE
This pragma requires runtime library functions which may not be implemented on all platforms, due to the possible need for operating system support.
Listing 29-13 on page 464 shows another example.
Listing 29-13. Example thread_safe_init
#pragma thread_safe_init on void thread_heavy_func()
{
// Multiple threads can now safely call this function:
CodeWarrior Development Studio for Advanced Packet Processing Build Tools Reference Manual, Rev.
10.2, 01/2016
464 Freescale Semiconductor, Inc.
Downloaden
Advertentie