From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23597 invoked by alias); 16 Oct 2014 14:43:50 -0000 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 Received: (qmail 23540 invoked by uid 89); 16 Oct 2014 14:43:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-qg0-f66.google.com Received: from mail-qg0-f66.google.com (HELO mail-qg0-f66.google.com) (209.85.192.66) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 16 Oct 2014 14:43:48 +0000 Received: by mail-qg0-f66.google.com with SMTP id a108so751082qge.5 for ; Thu, 16 Oct 2014 07:43:46 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.140.27.164 with SMTP id 33mr2517337qgx.57.1413470626518; Thu, 16 Oct 2014 07:43:46 -0700 (PDT) Received: by 10.140.85.11 with HTTP; Thu, 16 Oct 2014 07:43:46 -0700 (PDT) In-Reply-To: References: Date: Thu, 16 Oct 2014 14:43:00 -0000 Message-ID: Subject: Re: Compiling for single-threaded use (implicit threading support difference in 4.9.1 vs. 4.8.1) From: Johan Alfredsson To: Jonathan Wakely Cc: gcc-help Content-Type: text/plain; charset=UTF-8 X-SW-Source: 2014-10/txt/msg00098.txt.bz2 On Wed, Oct 15, 2014 at 6:44 AM, Jonathan Wakely wrote: > On 15 October 2014 10:14, Jonathan Wakely wrote: >> On 14 October 2014 18:29, Johan Alfredsson wrote: >>> Hi, >>> >>> I've noticed that g++ 4.9.1 behaves differently than 4.8.1 with >>> regards to (implicit) threading support. The 4.8.1 and 4.9.1 compilers >>> used were configured with identical options (*) to the configure >>> script (except --prefix) using --enable-threads=posix. >>> >>> For the following test-case >>> >>> #include >>> #include >>> >>> int main() { >>> std::string test("test"); >>> std::cout << test << std::endl; >>> } >>> >>> invoking g++ -O3 test.cc -o test, the 'test' binary is compiled with >>> multi-threading support using 4.9.1 but not using 4.8.1, e.g. for the >>> libstdc++ pool allocator a mutex is locked when allocating memory for >>> the string in the test program above while no such locking is present >>> in the 'test' binary compiled with 4.8.1. (There is also a difference >>> in that there is a weak symbol __pthread_key_create in the binary >>> compiled with 4.9.1 but no such thing for the 4.8.1 case.) >> >> Using a mutex in a single-threaded program would be a bug. Indeed. I don't use mutexes but things like the pool allocator does even if I don't want/need that (see below). >>> As my application is single-threaded, I don't want to pay the >>> performance penalty of mutexes etc. Hence, my question is if it is >>> possible to explicitly request gcc to compile my application in >>> single-threaded mode. >> >> It should happen automatically, there's no way to request it because >> there should be no need. >> >> I'll try to reproduce what you're seeing. > > I can't reproduce the problem with GCC 4.9.1 or trunk. I'm using a > Fedora 20 x86_64 system, so it's possible there's something different > on your distro. Sorry, my mistake. It turned out that librt was implicitly linked in in the 4.9.1 case. However, the only things I use from librt are high precision timers, so a switch to ensure no performance hit in my own code would be great. Regards, /Johan