[Bug 1248606] Re: Compiler optimisation affects reading of flag in thread

Dan Parnham parnham at gmail.com
Wed Nov 6 17:45:22 UTC 2013


Ok it seems this is not actually be a bug but a result of the more
aggressive optimisations present in gcc-2.8 affecting the existing code
which we should have marked up accordingly.

The solution, of course, is to inform the compiler that the variable in
question is 'volatile' so that it would not optimise out the reading of
that flag.


** Changed in: gcc-4.8 (Ubuntu)
       Status: Confirmed => Invalid

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

Title:
  Compiler optimisation affects reading of flag in thread

Status in “gcc-4.8” package in Ubuntu:
  Invalid

Bug description:
  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-jump-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

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



More information about the foundations-bugs mailing list