From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20374 invoked by alias); 21 May 2012 12:44:23 -0000 Received: (qmail 20364 invoked by uid 22791); 21 May 2012 12:44:22 -0000 X-SWARE-Spam-Status: No, hits=-3.5 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_BJ X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 21 May 2012 12:44:10 +0000 From: "o.mangold at googlemail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/53436] New: Volatile behaves strange with OpenMP Date: Mon, 21 May 2012 12:44:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: o.mangold at googlemail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 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: 2012-05/txt/msg02013.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53436 Bug #: 53436 Summary: Volatile behaves strange with OpenMP Classification: Unclassified Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization AssignedTo: unassigned@gcc.gnu.org ReportedBy: o.mangold@googlemail.com When I compile the program below (gcc 4.7.0) > gcc -g -O3 -std=c99 -fopenmp volatile.c I find, that the volatile is ignored (when optimizing with -O or higher) for the statement while(!x); >>From objdump I see that x is not reread for each loop > objdump -S a.out ... while(!x); sleep(1); printf("b finished\n"); 4007bf: bf 9c 08 40 00 mov $0x40089c,%edi 4007c4: e9 37 fe ff ff jmpq 400600 4007c9: eb fe jmp 4007c9 4007cb: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1) volatile bool x=false; #pragma omp parallel num_threads(2) shared(x) { if (omp_get_thread_num()==0) { sleep(1); 4007d0: bf 01 00 00 00 mov $0x1,%edi 4007d5: e8 66 fe ff ff callq 400640 ... At 4007c9 an unconditional (endless) loop is generated. I don't know if it is valid to use volatile this way in combination with OpenMP (maybe the standard doesn't cover it), but I guess that kind of optimization is at least a dangerous thing to do. --- volatile.c --- #include #include #include #include int main() { volatile bool x=false; #pragma omp parallel num_threads(2) { if (omp_get_thread_num()==0) { sleep(1); x=true; printf("a finished\n"); } else { while(!x); sleep(1); printf("b finished\n"); } } }