If you run this code
using Base.Threads
# mylock = ReentrantLock()
btask = @async while true
# global mylock
# lock(mylock)
print("B\n")
sleep(4/5)
# unlock(mylock)
end
atask = @async while true
# global mylock
# lock(mylock)
print("A")
sleep(1/2)
# unlock(mylock)
end
You get this output:
AB
AAB
AB
AAB
AB
AAB
AAB
AB
AAB
AB
Which is just right. If I uncomment the commented lines to add a mutex logic, it should result in AB AB AB. But what I get is just BBBBBB. So it looks like the first task is locking the lock, but then the second task can never lock it, as if it were never unlocked. What am I getting wrong?