This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/13684] local static object variable constructed once but ctors and dtors called multiple times on same memory when called in multiple threads


------- 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]