public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug driver/36081]  New: gcc optimizations and threads (pthread)
@ 2008-04-29 18:52 snes2002 at freenet dot de
  2008-04-29 18:55 ` [Bug driver/36081] " pinskia at gcc dot gnu dot org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: snes2002 at freenet dot de @ 2008-04-29 18:52 UTC (permalink / raw)
  To: gcc-bugs

gcc version 4.2.1 (Debian 4.2.1-3)
System: debian-installation from knoppix 5.1.1

When optimizations are turned on (-O, -O1, -O2, -O3),
two or more threads don't recognize when the value of a global variable
changes.
It doesn't matter if it's a global variable or a pointer to a local variable.
The change of its value by thread no 1 will not be recognized by thread no 2.


-- 
           Summary: gcc optimizations and threads (pthread)
           Product: gcc
           Version: 4.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: driver
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: snes2002 at freenet dot de


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36081


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug driver/36081] gcc optimizations and threads (pthread)
  2008-04-29 18:52 [Bug driver/36081] New: gcc optimizations and threads (pthread) snes2002 at freenet dot de
@ 2008-04-29 18:55 ` pinskia at gcc dot gnu dot org
  2008-04-29 18:55 ` snes2002 at freenet dot de
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-04-29 18:55 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2008-04-29 18:54 -------
This is correct behavior, you need either use volatile or use locks.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36081


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug driver/36081] gcc optimizations and threads (pthread)
  2008-04-29 18:52 [Bug driver/36081] New: gcc optimizations and threads (pthread) snes2002 at freenet dot de
  2008-04-29 18:55 ` [Bug driver/36081] " pinskia at gcc dot gnu dot org
@ 2008-04-29 18:55 ` snes2002 at freenet dot de
  2008-04-29 18:56 ` snes2002 at freenet dot de
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: snes2002 at freenet dot de @ 2008-04-29 18:55 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from snes2002 at freenet dot de  2008-04-29 18:54 -------
Created an attachment (id=15547)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=15547&action=view)
gcc output


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36081


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug driver/36081] gcc optimizations and threads (pthread)
  2008-04-29 18:52 [Bug driver/36081] New: gcc optimizations and threads (pthread) snes2002 at freenet dot de
  2008-04-29 18:55 ` [Bug driver/36081] " pinskia at gcc dot gnu dot org
  2008-04-29 18:55 ` snes2002 at freenet dot de
@ 2008-04-29 18:56 ` snes2002 at freenet dot de
  2008-04-29 18:57 ` snes2002 at freenet dot de
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: snes2002 at freenet dot de @ 2008-04-29 18:56 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from snes2002 at freenet dot de  2008-04-29 18:55 -------
Created an attachment (id=15548)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=15548&action=view)
c source


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36081


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug driver/36081] gcc optimizations and threads (pthread)
  2008-04-29 18:52 [Bug driver/36081] New: gcc optimizations and threads (pthread) snes2002 at freenet dot de
                   ` (2 preceding siblings ...)
  2008-04-29 18:56 ` snes2002 at freenet dot de
@ 2008-04-29 18:57 ` snes2002 at freenet dot de
  2008-04-29 18:58 ` snes2002 at freenet dot de
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: snes2002 at freenet dot de @ 2008-04-29 18:57 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from snes2002 at freenet dot de  2008-04-29 18:56 -------
Created an attachment (id=15549)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=15549&action=view)
preprocessed file


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36081


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug driver/36081] gcc optimizations and threads (pthread)
  2008-04-29 18:52 [Bug driver/36081] New: gcc optimizations and threads (pthread) snes2002 at freenet dot de
                   ` (3 preceding siblings ...)
  2008-04-29 18:57 ` snes2002 at freenet dot de
@ 2008-04-29 18:58 ` snes2002 at freenet dot de
  2008-04-29 19:00 ` snes2002 at freenet dot de
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: snes2002 at freenet dot de @ 2008-04-29 18:58 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from snes2002 at freenet dot de  2008-04-29 18:57 -------
Created an attachment (id=15550)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=15550&action=view)
assembler listing


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36081


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug driver/36081] gcc optimizations and threads (pthread)
  2008-04-29 18:52 [Bug driver/36081] New: gcc optimizations and threads (pthread) snes2002 at freenet dot de
                   ` (4 preceding siblings ...)
  2008-04-29 18:58 ` snes2002 at freenet dot de
@ 2008-04-29 19:00 ` snes2002 at freenet dot de
  2008-04-29 19:06 ` snes2002 at freenet dot de
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: snes2002 at freenet dot de @ 2008-04-29 19:00 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from snes2002 at freenet dot de  2008-04-29 18:59 -------
This c-code works with optimizations turned off.
With borland compiler it also works with optimizations turned on.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36081


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug driver/36081] gcc optimizations and threads (pthread)
  2008-04-29 18:52 [Bug driver/36081] New: gcc optimizations and threads (pthread) snes2002 at freenet dot de
                   ` (5 preceding siblings ...)
  2008-04-29 19:00 ` snes2002 at freenet dot de
@ 2008-04-29 19:06 ` snes2002 at freenet dot de
  2008-04-29 19:12 ` pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: snes2002 at freenet dot de @ 2008-04-29 19:06 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from snes2002 at freenet dot de  2008-04-29 19:06 -------
Subject: Re:  gcc optimizations and threads (pthread)

thanks for the quick reply.

But this code works without opimizations. Even with complex constructs.
For the solution of my problem i can't use lock's.
I don't want so serialize the threads, I want to use all 2 processors of my
dual-core.
And for syncing the threads, that's the easiest way.

Works fine whithout optimizations and also works with borland c++-compiler with
all optimizations.


----- original Nachricht --------

Betreff: [Bug driver/36081] gcc optimizations and threads (pthread)
Gesendet: Di 29 Apr 2008 20:55:20 CEST
Von: "pinskia at gcc dot gnu dot org"<gcc-bugzilla@gcc.gnu.org>

> 
> 
> ------- Comment #2 from pinskia at gcc dot gnu dot org  2008-04-29 18:54
> -------
> This is correct behavior, you need either use volatile or use locks.
> 
> 
> -- 
> 
> pinskia at gcc dot gnu dot org changed:
> 
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
> 
>              Status|UNCONFIRMED                 |RESOLVED
>          Resolution|                            |INVALID
> 
> 
> 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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug driver/36081] gcc optimizations and threads (pthread)
  2008-04-29 18:52 [Bug driver/36081] New: gcc optimizations and threads (pthread) snes2002 at freenet dot de
                   ` (6 preceding siblings ...)
  2008-04-29 19:06 ` snes2002 at freenet dot de
@ 2008-04-29 19:12 ` pinskia at gcc dot gnu dot org
  2008-04-30 12:26 ` snes2002 at freenet dot de
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-04-29 19:12 UTC (permalink / raw)
  To: gcc-bugs



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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug driver/36081] gcc optimizations and threads (pthread)
  2008-04-29 18:52 [Bug driver/36081] New: gcc optimizations and threads (pthread) snes2002 at freenet dot de
                   ` (7 preceding siblings ...)
  2008-04-29 19:12 ` pinskia at gcc dot gnu dot org
@ 2008-04-30 12:26 ` snes2002 at freenet dot de
  2008-05-03 10:27 ` snes2002 at freenet dot de
  2008-05-03 11:04 ` rguenth at gcc dot gnu dot org
  10 siblings, 0 replies; 12+ messages in thread
From: snes2002 at freenet dot de @ 2008-04-30 12:26 UTC (permalink / raw)
  To: gcc-bugs



------- 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"<gcc-bugzilla@gcc.gnu.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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug driver/36081] gcc optimizations and threads (pthread)
  2008-04-29 18:52 [Bug driver/36081] New: gcc optimizations and threads (pthread) snes2002 at freenet dot de
                   ` (8 preceding siblings ...)
  2008-04-30 12:26 ` snes2002 at freenet dot de
@ 2008-05-03 10:27 ` snes2002 at freenet dot de
  2008-05-03 11:04 ` rguenth at gcc dot gnu dot org
  10 siblings, 0 replies; 12+ messages in thread
From: snes2002 at freenet dot de @ 2008-05-03 10:27 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from snes2002 at freenet dot de  2008-05-03 10:26 -------
This is definitely a bug.
The same source-code must do the same thing, no matter what optimize-options
are enabled or disabled.


-- 

snes2002 at freenet dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36081


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug driver/36081] gcc optimizations and threads (pthread)
  2008-04-29 18:52 [Bug driver/36081] New: gcc optimizations and threads (pthread) snes2002 at freenet dot de
                   ` (9 preceding siblings ...)
  2008-05-03 10:27 ` snes2002 at freenet dot de
@ 2008-05-03 11:04 ` rguenth at gcc dot gnu dot org
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-05-03 11:04 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #11 from rguenth at gcc dot gnu dot org  2008-05-03 11:03 -------
No it must not.  If your program is bogus then it is bogus.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36081


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2008-05-03 11:04 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-29 18:52 [Bug driver/36081] New: gcc optimizations and threads (pthread) snes2002 at freenet dot de
2008-04-29 18:55 ` [Bug driver/36081] " pinskia at gcc dot gnu dot org
2008-04-29 18:55 ` snes2002 at freenet dot de
2008-04-29 18:56 ` snes2002 at freenet dot de
2008-04-29 18:57 ` snes2002 at freenet dot de
2008-04-29 18:58 ` snes2002 at freenet dot de
2008-04-29 19:00 ` snes2002 at freenet dot de
2008-04-29 19:06 ` snes2002 at freenet dot de
2008-04-29 19:12 ` pinskia at gcc dot gnu dot org
2008-04-30 12:26 ` snes2002 at freenet dot de
2008-05-03 10:27 ` snes2002 at freenet dot de
2008-05-03 11:04 ` rguenth at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).