From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 944 invoked by alias); 15 Jul 2004 13:54:31 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 775 invoked by uid 48); 15 Jul 2004 13:54:30 -0000 Date: Thu, 15 Jul 2004 13:54:00 -0000 Message-ID: <20040715135430.772.qmail@sourceware.org> From: "gianni at mariani dot ws" To: gcc-bugs@gcc.gnu.org In-Reply-To: <20040114172507.13684.evijaykumar@yahoo.com> References: <20040114172507.13684.evijaykumar@yahoo.com> Reply-To: gcc-bugzilla@gcc.gnu.org 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 X-Bugzilla-Reason: CC X-SW-Source: 2004-07/txt/msg01857.txt.bz2 List-Id: ------- 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