# Behavior of \`@time\` when using \`@spawn\` (in Julia 1.8 highlights blog post)

**URL:** <https://discourse.julialang.org/t/behavior-of-time-when-using-spawn-in-julia-1-8-highlights-blog-post/86125>\
**Category:** New to Julia\
**Tags:** multithreading\
**Created:** [August 22, 2022, 9:49am UTC](https://discourse.julialang.org/t/behavior-of-time-when-using-spawn-in-julia-1-8-highlights-blog-post/86125 "2022-08-22T09:49:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pierre-haessig](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pierre-haessig/32/217129_2.png) [@pierre-haessig](https://discourse.julialang.org/u/pierre-haessig)\
**Post date:** [August 22, 2022, 9:49am UTC](https://discourse.julialang.org/t/behavior-of-time-when-using-spawn-in-julia-1-8-highlights-blog-post/86125/1 "2022-08-22T09:49:43Z")

</div>

Hi,

I was just reading the [Julia 1.8 highlights](https://julialang.org/blog/2022/08/julia-1.8-highlights/) blog post and I have a question about multithreading (a Julia feature I have never used).

In the section about the new [default scheduler for `@threads`](https://julialang.org/blog/2022/08/julia-1.8-highlights/#new_default_scheduler_for_threads), there is the following example running on Julia 1.8:

```julia
julia> @time begin
            Threads.@spawn busywait(5)
            Threads.@threads for i in 1:Threads.nthreads()
                busywait(1)
            end
        end
2.012056 seconds (16.05 k allocations: 883.919 KiB, 0.66% compilation time)

```

Since the `busywait(5)` call should take 5 s to complete, I just want to be sure that I understand correctly the behavior of `@time` when using `@spawn`. My understanding of this code is that at the end of the timed block (which took 2s), the thread which runs `busywait(5)` is _not finished_ (and will take ~3s to complete). _Am I right?_

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [August 22, 2022, 10:00am UTC](https://discourse.julialang.org/t/behavior-of-time-when-using-spawn-in-julia-1-8-highlights-blog-post/86125/2 "2022-08-22T10:00:06Z")

</div>

Yes, that is correct. We can test your hypothesis by slightly modifying your example:

```julia
julia> @time begin
           t = time()
           Threads.@spawn (busywait(5); println(time() - t))
           Threads.@threads for i in 1:Threads.nthreads()
               busywait(1)
           end
       end
  2.062341 seconds (43.90 k allocations: 2.938 MiB, 3.01% compilation time)

julia> 5.037096977233887 # printed after the 5s have passed

```

---

<div class="post-metadata">

**Author:** ![pierre-haessig](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pierre-haessig/32/217129_2.png) [@pierre-haessig](https://discourse.julialang.org/u/pierre-haessig)\
**Post date:** [August 22, 2022, 4:58pm UTC](https://discourse.julialang.org/t/behavior-of-time-when-using-spawn-in-julia-1-8-highlights-blog-post/86125/3 "2022-08-22T16:58:16Z")

</div>

Thanks!
