File tree 1 file changed +6
-4
lines changed
constantine/threadpool/crossthread
1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -142,16 +142,18 @@ proc isCompleted*(task: ptr Task): bool {.inline.} =
142
142
proc setCompleted * (task: ptr Task ) {.inline .} =
143
143
# # Set a task to `complete`
144
144
# # Wake a waiter thread if there is one
145
- task.state.completed.store (1 , moRelease)
146
- let waiter = task.state.synchro.load (moAcquire)
145
+ task.state.completed.store (1 , moRelease) # Correctness on weak memory models like ARM: tests/t_ethereum_eip4844_deneb_kzg_parallel.nim
146
+ fence (moSequentiallyConsistent) # Avoid deadlock on Windows: benchmarks-threadpool/fibonacci/threadpool_fib.nim
147
+ let waiter = task.state.synchro.load (moRelaxed)
147
148
if (waiter and kWaiterMask) != SentinelWaiter :
148
149
task.state.completed.wake ()
149
150
150
151
proc sleepUntilComplete * (task: ptr Task , waiterID: int32 ) {.inline .} =
151
152
# # Sleep while waiting for task completion
152
153
let waiter = (cast [uint32 ](waiterID) shl kWaiterShift) - SentinelWaiter
153
- discard task.state.synchro.fetchAdd (waiter, moRelease)
154
- while task.state.completed.load (moAcquire) == 0 :
154
+ discard task.state.synchro.fetchAdd (waiter, moRelaxed)
155
+ fence (moAcquire)
156
+ while task.state.completed.load (moRelaxed) == 0 :
155
157
task.state.completed.wait (0 )
156
158
157
159
# Leapfrogging synchronization
You can’t perform that action at this time.
0 commit comments