Lock inversion in forkProcess
When looking at !1603 (closed) I found the following potential deadlock.
WARNING: ThreadSanitizer: lock-order-inversion (potential deadlock) (pid=21208)
Cycle in lock order graph: M10 (0x7b6400000948) => M38 (0x7b30000001c0) => M10
Mutex M38 acquired here while holding mutex M10 in thread T1:
#0 pthread_mutex_lock <null> (libtsan.so.0+0x00000003c4df)
#1 giveCapabilityToTask rts/Capability.c:483 (posix014+0x00000072b4dc)
#2 releaseCapability_ rts/Capability.c:555 (posix014+0x00000072c906)
#3 yieldCapability rts/Capability.c:922 (posix014+0x00000072cf6a)
#4 scheduleYield rts/Schedule.c:681 (posix014+0x000000738c32)
#5 schedule rts/Schedule.c:295 (posix014+0x000000738c32)
#6 scheduleWorker rts/Schedule.c:2570 (posix014+0x00000073b2be)
#7 workerStart rts/Task.c:445 (posix014+0x000000741ed5)
#8 <null> <null> (libtsan.so.0+0x000000028d5b)
Hint: use TSAN_OPTIONS=second_deadlock_stack=1 to get more informative warning message
Mutex M10 acquired here while holding mutex M38 in main thread:
#0 pthread_mutex_lock <null> (libtsan.so.0+0x00000003c4df)
#1 forkProcess rts/Schedule.c:1985 (posix014+0x000000739d4e)
#2 <null> <null> (posix014+0x00000041859e)
#3 scheduleWaitThread rts/Schedule.c:2553 (posix014+0x00000073b24d)
#4 rts_evalLazyIO rts/RtsAPI.c:530 (posix014+0x000000782ba1)
#5 hs_main rts/RtsMain.c:72 (posix014+0x000000732ac5)
#6 main <null> (posix014+0x000000412fc1)
Thread T1 (tid=21210, running) created by main thread at:
#0 pthread_create <null> (libtsan.so.0+0x00000002c010)
#1 createOSThread rts/posix/OSThreads.c:137 (posix014+0x000000766dbf)
#2 startWorkerTask rts/Task.c:497 (posix014+0x0000007428ea)
#3 startWorkerTasks rts/Schedule.c:2606 (posix014+0x00000073b40c)
#4 initScheduler rts/Schedule.c:2657 (posix014+0x00000073b40c)
#5 hs_init_ghc rts/RtsStartup.c:237 (posix014+0x0000007338dc)
#6 hs_main rts/RtsMain.c:57 (posix014+0x000000732a9b)
#7 main <null> (posix014+0x000000412fc1)
SUMMARY: ThreadSanitizer: lock-order-inversion (potential deadlock) (/nix/store/c7hj2bk4aqgpb3q0h5xhq7lag0lq3jm7-gcc-7.4.0-lib/lib/libtsan.so.0+0x3c4df) in pthread_mutex_lock