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

**URL:** <https://discourse.julialang.org/t/missing-println-output-with-wait-event-println-done/122137>\
**Category:** General Usage\
**Tags:** question\
**Created:** [November 1, 2024, 2:20pm UTC](https://discourse.julialang.org/t/missing-println-output-with-wait-event-println-done/122137 "2024-11-01T14:20:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SunnyUser](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sunnyuser/32/206001_2.png) [@SunnyUser](https://discourse.julialang.org/u/SunnyUser)\
**Post date:** [November 1, 2024, 2:20pm UTC](https://discourse.julialang.org/t/missing-println-output-with-wait-event-println-done/122137/1 "2024-11-01T14:20:43Z")

</div>

Hi all 🙂

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

```julia
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

---

<div class="post-metadata">

**Author:** ![BioTurboNick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bioturbonick/32/6380_2.png) [@BioTurboNick](https://discourse.julialang.org/u/BioTurboNick)\
**Post date:** [November 1, 2024, 3:05pm UTC](https://discourse.julialang.org/t/missing-println-output-with-wait-event-println-done/122137/2 "2024-11-01T15:05:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Impressium](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/impressium/32/19575_2.png) [@Impressium](https://discourse.julialang.org/u/Impressium)\
**Post date:** [November 1, 2024, 4:43pm UTC](https://discourse.julialang.org/t/missing-println-output-with-wait-event-println-done/122137/3 "2024-11-01T16:43:55Z")

</div>

Is printing not thread safe?

---

<div class="post-metadata">

**Author:** ![eldee](https://avatars.discourse-cdn.com/v4/letter/e/b5a626/32.png) [@eldee](https://discourse.julialang.org/u/eldee)\
**Post date:** [November 1, 2024, 6:21pm UTC](https://discourse.julialang.org/t/missing-println-output-with-wait-event-println-done/122137/4 "2024-11-01T18:21:09Z")

</div>

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-repl
> 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-repl
> 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
> 
> ```
