# Simple example of @threads

**URL:** <https://discourse.julialang.org/t/simple-example-of-threads/83049>\
**Category:** Performance\
**Tags:** multithreading\
**Created:** [June 20, 2022, 6:42am UTC](https://discourse.julialang.org/t/simple-example-of-threads/83049 "2022-06-20T06:42:31Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![amrods](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amrods/32/2543_2.png) [@amrods](https://discourse.julialang.org/u/amrods)\
**Post date:** [June 20, 2022, 8:29am UTC](https://discourse.julialang.org/t/simple-example-of-threads/83049/3 "2022-06-20T08:29:29Z")

</div>

I’d like to keep the structure of a `for` loop because I have something like this:

```julia
function func(R)
    b = zero(paramvec)
    for i in 1:R
        sdata = datasimulator() # returns a vector of data
        b += estimatemodel(sdata) # returns a vector of parameters
    end
    avgb = b ./ R # averages parameters across simulations
    return likelihood(avgb)
end

```

Can that be done?

---

_[View the full topic](https://discourse.julialang.org/t/simple-example-of-threads/83049)._
