From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9001 invoked by alias); 30 Apr 2008 12:26:45 -0000 Received: (qmail 8873 invoked by alias); 30 Apr 2008 12:26:03 -0000 Date: Wed, 30 Apr 2008 12:26:00 -0000 Message-ID: <20080430122603.8872.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug driver/36081] gcc optimizations and threads (pthread) In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "snes2002 at freenet dot de" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2008-04/txt/msg02132.txt.bz2 ------- Comment #9 from snes2002 at freenet dot de 2008-04-30 12:26 ------- Subject: Re: gcc optimizations and threads (pthread) Hello, I read about mutexes, cond_wait and cond_signal. When I use these things instead of "busy loop" there is no performance gain at all for my problem (=generating the first 50000 prime numbers). I tested the execution-times of all variants: Single-thread (compiled with -O2) : 17,5 s Double-thread with busy-loop (compiled with -O0) : 11 s Double-thread with mutexes (compiled with -O2) : 47,1 s !!! But all this is not the problem or the reason why I'm reporting this. The problem is, that the same code (whatever it does) compiled with "gcc -O0" or "bcc32 -O0" (with wine) or "bcc32 -O2" works. But if compiled with "gcc -O2" it doesn't work. In this case the second thread doesn't read or dereference the actual pointer. It seems to be cached somehow in a register and not read realtime. If there are additional exit-conditions in loops (because of speed-optimization) they won't be recognized. ----- original Nachricht -------- Betreff: [Bug driver/36081] gcc optimizations and threads (pthread) Gesendet: Di 29 Apr 2008 21:11:58 CEST Von: "pinskia at gcc dot gnu dot org" > > > ------- Comment #8 from pinskia at gcc dot gnu dot org 2008-04-29 19:11 > ------- > >And for syncing the threads, that's the easiest way. > > Use mutexes then, they are designed exactly for this. > > >I don't want so serialize the threads, I want to use all 2 processors of > my > dual-core. > > You are serializing them by doing a busy loop. In fact using a busy loop > will > just make the CPUs spin without doing anything except for checking a > condition. > Using a mutex allows for other stuff to happen while that thread is > waiting > for more work to do. > > I guess you need to read up on threading programming more because right now > you > are causing extra work to happen on thread for no reason. > > -- Pinski > > > -- > > > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36081 > > ------- You are receiving this mail because: ------- > You reported the bug, or are watching the reporter. > --- original Nachricht Ende ---- -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36081