Is it possible that the -O2 optimization flag reorders the code, thereby making it possible for a multi-threaded application to work as intended?
As an example of what I mean by un-intended behavior when re-compiling code: a variable declared (by the programmer) that must be created for each thread is moved outside of #pragma omp parallal , so that only one single copy is created, a common one for all threads.
source share