Public bug reported:

We have a thread pool implementation (from before std::async became
available). But the update from gcc 4.7 to 4.8 has broken the
implementation. We have since solved it but the way it was broken
suggests a bug in the compiler optimisation.

I have attached a fully working example which can be compiled as follows:
g++ -o gcc-thread-bug gcc-thread-bug.cpp -O3 -std=c++11 -pthread 
-Wl,--no-as-needed

When run the loop will get stuck checking the status of the threads.

If the line setting the flag to false first is uncommented then it works
(even though that should have no effect on the logic of the loop). If
the optimisations (-O3) are disabled then it works.

Our implementation has had heavy use for some time now and it is only
the switch to gcc-4.8 that seems to have stopped it working.

We've narrowed it down to the following optimisations:

-ftree-pre -ftree-vrp -O but disable EVERY FLAG that -O sets except for:
-ftree-sra -ftree-dce -ftree-ch -ftree-ccp -finline -finline-atomics
-fira-hoist-pressure -ftree-loop-im -ftree-loop-optimize

i.e.:
g++ -o gcc-thread-bug gcc-thread-bug.cpp -std=c++11 -pthread -Wl,--no-as-needed 
-O -ftree-pre -ftree-vrp -fno-auto-inc-dec -fno-compare-elim 
-fno-cprop-registers -fno-dce -fno-defer-pop -fno-delayed-branch -fno-dse 
-fno-guess-branch-probability -fno-if-conversion2 -fno-if-conversion 
-fno-ipa-pure-const -fno-ipa-profile -fno-ipa-reference -fno-merge-constants 
-fno-split-wide-types -fno-tree-bit-ccp -fno-tree-builtin-call-dce -ftree-ccp 
-ftree-ch -fno-tree-copyrename -ftree-dce -fno-tree-dominator-opts 
-fno-tree-dse -fno-tree-forwprop -fno-tree-fre -fno-tree-phiprop -fno-tree-slsr 
-ftree-sra -fno-tree-pta -fno-tree-ter -fno-unit-at-a-time 
-fno-combine-stack-adjustments -fno-forward-propagate 
-fno-inline-functions-called-once -fno-shrink-wrap -fno-tree-builtin-call-dce 
-fno-tree-copy-prop -fno-tree-sink -fno-aggressive-loop-optimizations 
-fno-asynchronous-unwind-tables -fno-branch-count-reg -fno-common 
-fno-delete-null-pointer-checks -fno-early-inlining -fno-gcse-lm -fno-ivopts 
-fno-jum
 p-tables -fno-math-errno -fno-move-loop-invariants -fno-peephole 
-fno-prefetch-loop-arrays -fno-rename-registers -fno-rtti 
-fno-sched-critical-path-heuristic -fno-sched-dep-count-heuristic 
-fno-sched-group-heuristic -fno-sched-interblock -fno-sched-last-insn-heuristic 
-fno-sched-rank-heuristic -fno-sched-spec -fno-sched-spec-insn-heuristic 
-fno-sched-stalled-insns-dep -fno-short-enums -fno-signed-zeros 
-fno-split-ivs-in-unroller -fno-toplevel-reorder -fno-trapping-math 
-fno-tree-coalesce-vars -fno-tree-cselim -fno-tree-loop-if-convert 
-fno-tree-loop-ivcanon -fno-tree-reassoc -fno-tree-scev-cprop 
-fno-tree-slp-vectorize -fno-tree-vect-loop-version -fno-var-tracking 
-fno-var-tracking-assignments -fno-web

** Affects: gcc-4.8 (Ubuntu)
     Importance: Undecided
         Status: New

** Attachment added: "gcc-thread-bug.cpp"
   
https://bugs.launchpad.net/bugs/1248606/+attachment/3901628/+files/gcc-thread-bug.cpp

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1248606

Title:
  Compiler optimisation affects reading of flag in thread

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/gcc-4.8/+bug/1248606/+subscriptions

-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to