FPC optimization disables threading on Darwin
Original Reporter info from Mantis: crlab @neurolabusc1
-
Reporter name: Chris Rorden
Original Reporter info from Mantis: crlab @neurolabusc1
- Reporter name: Chris Rorden
Description:
This seems to be specific to MacOS Darwin, as it does not happen on Linux. When I compile a project with an optimization level higher than -o1, the multi-threading is disabled. This is not only in the simple program attached (where one could argue that optimization removes useless calls, but also to real world projects like this one: https://github.com/neurolabusc/DistanceFields which includes sample data
Steps to reproduce:
Compile a project with MacOS using -O1 and note threading works. Recompile with -O2 or -O3 and notice threads are run sequentially. It is not only the order of the threads (which could be random) but the speed which suggests single threading.
Using sample project
https://wiki.freepascal.org/Parallel_procedures#Simple_example
$fpc -O1 -CX -Xs -XX tester
Free Pascal Compiler version 3.0.4 [2018/09/30] for x86_64
Copyright (c) 1993-2017 by Florian Klaempfl and others
...
$./tester
1
5
4
3
2
$fpc -O2 -CX -Xs -XX tester
Free Pascal Compiler version 3.0.4 [2018/09/30] for x86_64
...
$./tester
1
2
3
4
5
Additional information:
There is a patch attached for a file belonging to Lazarus, so I assume this issue does not belong in "Lazarus-CCR".
Mantis conversion info:
- Mantis ID: 36325
- OS: Darwin
- OS Build: 10.11.6
- Build: 3.0.4 [2018/09/30] for x86_64
- Platform: MacBook 2012 Retina 13"
- Fixed in revision: 62277 (#a2486e3c)