Missing `println` output with `wait(::Event); println("done")`

Hi all :slight_smile:

Can you check if the done2 is also missing for you?
Here is my code:

julia> e = Base.Event()
Base.Event(Base.GenericCondition{ReentrantLock}(Base.IntrusiveLinkedList{Task}(nothing, nothing), ReentrantLock(nothing, 0x00000000, 0x00, Base.GenericCondition{Base.Threads.SpinLock}(Base.IntrusiveLinkedList{Task}(nothing, nothing), Base.Threads.SpinLock(0)), (8, 0, -1))), false, false)

julia> [Threads.@spawn begin wait(e); println("done$i") end for i in 1:10]
10-element Vector{Task}:
 Task (runnable, started) @0x0000014db88ea6d0
 Task (runnable, started) @0x0000014db88ea8c0
 Task (runnable, started) @0x0000014db88eaab0
 Task (runnable, started) @0x0000014db88eaca0
 Task (runnable, started) @0x0000014db88eae90
 Task (runnable, started) @0x0000014db88eb080
 Task (runnable, started) @0x0000014db88eb270
 Task (runnable, started) @0x0000014db88eb460
 Task (runnable, started) @0x0000014db88eb650
 Task (runnable, started) @0x0000014db88eb840

julia> notify(e)
done1
# missing done2
julia>
done3
done4
done5
done6
done7
done8
done9
done10

Should we fix it? Is it only a repl problem?

Cheers

I’m guessing the REPL prompt is competing with done2 for printing to the terminal.

Is printing not thread safe?

Note that you can ‘solve’ the problem in the REPL by adding a sleep after the notify, in order to give enough time to print to stdio, confirming @BioTurboNick 's hypothesis.

No sleep
julia> e = Base.Event();

julia> [Threads.@spawn begin wait(e); println("done$i") end for i in 1:10]
10-element Vector{Task}:
 Task (runnable) @0x0000015fc48f64e0
 Task (runnable) @0x0000015fc48f66d0
 Task (runnable) @0x0000015fc48f68c0
 Task (runnable) @0x0000015fc48f6ab0
 Task (runnable) @0x0000015fc48f6ca0
 Task (runnable) @0x0000015fc48f6e90
 Task (runnable) @0x0000015fc48f7080
 Task (runnable) @0x0000015fc48f7270
 Task (runnable) @0x0000015fc48f7460
 Task (runnable) @0x0000015fc48f7650

julia> notify(e)
done7

julia> done9
julia> done8
done1
done2
done3
done10
done4
done6
done5
With sleep
julia> e = Base.Event();

julia> [Threads.@spawn begin wait(e); println("done$i") end for i in 1:10]
10-element Vector{Task}:
 Task (runnable) @0x0000015fc48f7840
 Task (runnable) @0x0000015fc48f7a30
 Task (runnable) @0x0000015fc48f7c20
 Task (runnable) @0x0000015fc48f7e10
 Task (runnable) @0x0000015f9ba5c010
 Task (runnable) @0x0000015f9ba5c200
 Task (runnable) @0x0000015f9ba5c3f0
 Task (runnable) @0x0000015f9ba5c5e0
 Task (runnable) @0x0000015f9ba5c7d0
 Task (runnable) @0x0000015f9ba5c9c0

julia> notify(e); sleep(0.1)
done3
done5
done4
done9
done7
done1
done6
done8
done2
done10