Skip to content

Commit 3b97f9c

Browse files
committed
Lock condvar to wait, restore sticky after notify
1 parent 58dba62 commit 3b97f9c

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/GIL/GlobalInterpreterLock.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ function Base.pop!(task_stack::TaskStack)::Task
6262

6363
C.PyGILState_Release(gil_state)
6464

65-
# Restore sticky state after releasing the GIL
66-
task.sticky = sticky
67-
6865
Base.lock(task_stack.condvar) do
6966
notify(task_stack.condvar)
7067
end
7168

69+
# Restore sticky state after releasing the GIL
70+
task.sticky = sticky
71+
7272
return task
7373
end
7474
Base.in(task::Task, task_stack::TaskStack) = haskey(task_stack.count)
@@ -146,7 +146,9 @@ function Base.unlock(gil::GlobalInterpreterLock)
146146
else
147147
# This task does not own the GIL. Wait to unlock the GIL until
148148
# another task successfully unlocks the GIL.
149-
wait(lock_owner.condvar)
149+
Base.lock(lock_owner.condvar) do
150+
wait(lock_owner.condvar)
151+
end
150152
end
151153
last_owner = if isempty(lock_owner)
152154
current_task()

0 commit comments

Comments
 (0)