# Is there barrier condition in Mulit-threading?

**URL:** https://discourse.julialang.org/t/is-there-barrier-condition-in-mulit-threading/95157
**Category:** General Usage
**Tags:** question
**Created:** [February 24, 2023, 5:45pm UTC](https://discourse.julialang.org/t/is-there-barrier-condition-in-mulit-threading/95157 "2023-02-24T17:45:09Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Amro](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Amro](https://discourse.julialang.org/u/Amro)
#### Post date: [February 24, 2023, 5:45pm UTC](https://discourse.julialang.org/t/is-there-barrier-condition-in-mulit-threading/95157/1 "2023-02-24T17:45:09Z")

</div>

Is there a barrier synchronization primitive to synchronize multiple threads created by `@threads` and ensure that they all reach a certain point in a for loop before continuing execution. Such as below?

```julia
barrier = Threads.Barrier(nthreads())
@threads for i in 1:nthreads()
  for j in 1:10
    # do some work

    # wait for other threads to reach the barrier
    Threads.wait(barrier)

    # do some more work
  end
end

```
