Являются ли статические переменные функции потокобезопасными в GCC?
В примере кода
void foo()
{
static Bar b;
...
}
составлено сGCC это гарантировано, чтоb
будет создан и инициализирован потокобезопасным способом?
В справочной странице gcc нашел-fno-threadsafe-statics опция командной строки:
Do not emit the extra code to use the routines specified in the C++ ABI for thread-safe initialization of local statics. You can use this option to reduce code size slightly in code that doesn't need to be thread-safe.
Does it mean, that local statics are thread-safe by default with GCC ? So no reason to put explicit guarding e.g. with pthread_mutex_lock/unlock
?
How to write portable code - how to check if compiler will add its guards ? Or is it better to turn off this feature of GCC ?