Created
September 12, 2019 12:28
-
-
Save defufna/be79a3e1690d72246b903147cc0f37dd to your computer and use it in GitHub Desktop.
Deadlock on program tremination
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package; | |
import kha.System; | |
import haxe.ds.Vector; | |
class Main { | |
public static function main() { | |
var v:Vector<Int>; | |
for (i in 0...8192){ | |
v = new Vector(256); | |
for(j in 0...v.length){ | |
v[j] = j; | |
} | |
} | |
trace("Exiting...."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This sample code will fail to terminate when run on Linux target. The reason is deadlock between main thread and garbage collector thread.
Here is an example stack trace:
Main Thread
GC Thread
What happens is that on main thread termination, all HxSemaphore destructors are called. They end up trying to destroy pthread_cond, which GC threads are waiting on.
I ran this same sample on vanilla Haxe and it doesn't hang there. In default hxcpp implementation pthread_conds are not destroyed on main thread termination, and GC threads are left for OS to clean up.
The simple solution is to comment out HxSemaphore destructor in Backends/Kore/khacpp/include/hx/Thread.h, but I'm not sure if that's the best approach.