Data race between setNumCapabilities and itimer
While looking at !1603 (closed)
==================
WARNING: ThreadSanitizer: data race (pid=5135)
Atomic write of size 4 at 0x7b6400001328 by thread T2:
#0 __tsan_atomic32_store <null> (libtsan.so.0+0x000000061bf1)
#1 contextSwitchCapability rts/Capability.h:473 (nursery-chunks1+0x00000072566d)
#2 contextSwitchAllCapabilities rts/Capability.c:449 (nursery-chunks1+0x00000072566d)
#3 handle_tick rts/Timer.c:49 (nursery-chunks1+0x00000073e13f)
#4 itimer_thread_func rts/posix/itimer/Pthread.c:148 (nursery-chunks1+0x00000075eefc)
#5 <null> <null> (libtsan.so.0+0x000000028d5b)
Previous write of size 8 at 0x7b6400001328 by main thread:
#0 malloc <null> (libtsan.so.0+0x00000002b251)
#1 stgMallocBytes rts/RtsUtils.c:64 (nursery-chunks1+0x00000072cd0b)
#2 moreCapabilities rts/Capability.c:425 (nursery-chunks1+0x000000725321)
#3 setNumCapabilities rts/Schedule.c:2251 (nursery-chunks1+0x0000007339e5)
#4 Main_main1_info <null> (nursery-chunks1+0x00000041318e)
#5 scheduleWaitThread rts/Schedule.c:2555 (nursery-chunks1+0x0000007343cd)
#6 rts_evalLazyIO rts/RtsAPI.c:530 (nursery-chunks1+0x00000077bd51)
#7 hs_main rts/RtsMain.c:72 (nursery-chunks1+0x00000072bab5)
#8 main <null> (nursery-chunks1+0x000000413389)
Location is heap block of size 1280 at 0x7b6400000f00 allocated by main thread:
#0 malloc <null> (libtsan.so.0+0x00000002b251)
#1 stgMallocBytes rts/RtsUtils.c:64 (nursery-chunks1+0x00000072cd0b)
#2 moreCapabilities rts/Capability.c:425 (nursery-chunks1+0x000000725321)
#3 setNumCapabilities rts/Schedule.c:2251 (nursery-chunks1+0x0000007339e5)
#4 Main_main1_info <null> (nursery-chunks1+0x00000041318e)
#5 scheduleWaitThread rts/Schedule.c:2555 (nursery-chunks1+0x0000007343cd)
#6 rts_evalLazyIO rts/RtsAPI.c:530 (nursery-chunks1+0x00000077bd51)
#7 hs_main rts/RtsMain.c:72 (nursery-chunks1+0x00000072bab5)
#8 main <null> (nursery-chunks1+0x000000413389)
Thread T2 'ghc_ticker' (tid=5138, running) created by main thread at:
#0 pthread_create <null> (libtsan.so.0+0x00000002c010)
#1 initTicker rts/posix/itimer/Pthread.c:171 (nursery-chunks1+0x00000075f0c0)
#2 initTimer rts/Timer.c:112 (nursery-chunks1+0x00000073ded2)
#3 hs_init_ghc rts/RtsStartup.c:310 (nursery-chunks1+0x00000072c9d5)
#4 hs_main rts/RtsMain.c:57 (nursery-chunks1+0x00000072ba8b)
#5 main <null> (nursery-chunks1+0x000000413389)
SUMMARY: ThreadSanitizer: data race (/nix/store/c7hj2bk4aqgpb3q0h5xhq7lag0lq3jm7-gcc-7.4.0-lib/lib/libtsan.so.0+0x61bf1) in __tsan_atomic32_store
Edited by Ben Gamari