# How to run two tasks on parallel?

**URL:** <https://discourse.julialang.org/t/how-to-run-two-tasks-on-parallel/86902>\
**Category:** Performance\
**Tags:** parallel\
**Created:** [September 7, 2022, 4:34pm UTC](https://discourse.julialang.org/t/how-to-run-two-tasks-on-parallel/86902 "2022-09-07T16:34:45Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![jmair](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jmair/32/35117_2.png) [@jmair](https://discourse.julialang.org/u/jmair)\
**Post date:** [September 8, 2022, 9:50pm UTC](https://discourse.julialang.org/t/how-to-run-two-tasks-on-parallel/86902/10 "2022-09-08T21:50:29Z")

</div>

> [@Amro](#):
>
> ```julia
> for n in tmin+1:tmax
> X[n] = D1[n]*D2[n] + Y[n-1]; # I want to make it as Thread-1
> Y[n] = D1[n-1]*D2[n-1] + X[n-1]; # I want to make it as Thread-2
> end
> 
> ```

Although, your problem is probably better suited to just spawning threads:

```julia
for n in tmin+1:tmax
   Xn = Threads.@spawn D1[n]*D2[n] + Y[n-1];
   Yn = Threads.@spawn D1[n-1]*D2[n-1] + X[n-1];
   X[n] = fetch(Xn)
   Y[n] = fetch(Yn)
end

```

---

_[View the full topic](https://discourse.julialang.org/t/how-to-run-two-tasks-on-parallel/86902)._
