This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/13684] local static object variable constructed once but ctors and dtors called multiple times on same memory when called in multiple threads
- From: "gianni at mariani dot ws" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 15 Jul 2004 13:54:30 -0000
- Subject: [Bug c++/13684] local static object variable constructed once but ctors and dtors called multiple times on same memory when called in multiple threads
- References: <20040114172507.13684.evijaykumar@yahoo.com>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- 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