[Bug c++/13684] local static object variable constructed once but ctors and dtors called multiple times on same memory when called in multiple threads
gianni at mariani dot ws
gcc-bugzilla@gcc.gnu.org
Thu Jul 15 13:54:00 GMT 2004
------- Additional Comments From gianni at mariani dot ws 2004-07-15 13:54 -------
Zack's code may have been missing the details but the code below is still
perfectly valid.
if (guard) {
if (__cxa_guard_acquire (&guard)) {
// construct variable.
__cxa_guard_release (&guard)
}
}
If you take these definitions for aquire/release functions.
bool __cxa_guard_acquire ( volatile bool * pguard )
{
__lock_reentrant_mutex( & global_mutex );
if ( ! * pguard )
{
__unlock_reentrant_mutex( &global_mutex );
return false;
}
return true;
}
void __cxa_guard_release (bool * guard)
{
* guard = false;
__unlock_reentrant_mutex( &global_mutex );
}
I'd imagine that the sense of the guard is more like "is initialized" so the
code below is more like somthing that could be plugged in.
if (! is_initialized) {
if (__cxa_guard_acquire(is_initialized)) {
// construct variable.
__cxa_guard_release(is_initialized)
}
}
And these would be the corresponding aquire/release functions.
bool __cxa_guard_acquire ( volatile bool & is_initialized )
{
__lock_reentrant_mutex( & global_mutex );
if ( ! is_initialized )
{
__unlock_reentrant_mutex( &global_mutex );
return true;
}
return false;
}
void __cxa_guard_release( volatile bool & is_initialized )
{
is_initialized = true;
__unlock_reentrant_mutex( &global_mutex );
}
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13684
More information about the Gcc-bugs
mailing list