From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1344 invoked by alias); 6 Mar 2007 12:44:27 -0000 Received: (qmail 1331 invoked by uid 22791); 6 Mar 2007 12:44:25 -0000 X-Spam-Check-By: sourceware.org Received: from exprod6og54.obsmtp.com (HELO exprod6og54.obsmtp.com) (64.18.1.189) by sourceware.org (qpsmtpd/0.31) with SMTP; Tue, 06 Mar 2007 12:44:19 +0000 Received: from source ([192.150.11.134]) by exprod6ob54.postini.com ([64.18.5.12]) with SMTP; Tue, 06 Mar 2007 04:44:08 PST Received: from inner-relay-3.eur.adobe.com (inner-relay-3.adobe.com [192.150.20.198] (may be forged)) by outbound-smtp-1.corp.adobe.com (8.12.10/8.12.10) with ESMTP id l26ChqD1013034; Tue, 6 Mar 2007 04:43:53 -0800 (PST) Received: from fe2.corp.adobe.com (fe2.corp.adobe.com [10.8.192.72]) by inner-relay-3.eur.adobe.com (8.12.10/8.12.9) with ESMTP id l26Ci5mA016266; Tue, 6 Mar 2007 04:44:05 -0800 (PST) Received: from namailgen.corp.adobe.com ([10.8.192.91]) by fe2.corp.adobe.com with Microsoft SMTPSVC(6.0.3790.1830); Tue, 6 Mar 2007 04:44:04 -0800 Received: from 10.32.16.88 ([10.32.16.88]) by namailgen.corp.adobe.com ([10.8.192.91]) via Exchange Front-End Server namailhost.corp.adobe.com ([10.8.192.70]) with Microsoft Exchange Server HTTP-DAV ; Tue, 6 Mar 2007 12:44:04 +0000 User-Agent: Microsoft-Entourage/11.3.3.061214 Date: Tue, 06 Mar 2007 12:46:00 -0000 Subject: Re: G++ and constructors From: John Love-Jensen To: Sean MacLennan , MSX to GCC Message-ID: In-Reply-To: <45ECA343.5030306@seanm.ca> Mime-version: 1.0 Content-type: text/plain; charset="US-ASCII" Content-transfer-encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2007-03/txt/msg00076.txt.bz2 Hi Sean, > I don't need work-arounds, I just need to know if the code ever could be > split. Yes. The code can be split (assuming that "lock()" and "unlock()" are not performing some thread "critical protection" locking for you). Although you didn't ask for work-arounds, here's a work-around that works for GCC, but may not work in C++ in general*. GCC uses threading protection for static objects. So this variant of your routine, in GCC, should be thread safe: ---------------------------------------------------------------------- myclass* myclass::init_instance() // private: static { return new myclass(); } myclass* myclass::get_instance() // public: static { static myclass* instance = InitInstance(); return instance; } ---------------------------------------------------------------------- HTH, --Eljay * since ISO 14882 C++ punted on the whole threading issue**. ** ... and on a standard C++ ABI, on modules, on... well, lots of stuff for various reasons***. *** some good reasons, some bad reasons -- depending on one's point of view.