# Getting different result from serial and multithreaded code in Julia

**URL:** <https://discourse.julialang.org/t/getting-different-result-from-serial-and-multithreaded-code-in-julia/93257>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [January 20, 2023, 10:36am UTC](https://discourse.julialang.org/t/getting-different-result-from-serial-and-multithreaded-code-in-julia/93257 "2023-01-20T10:36:44Z")\
**Posts on this page:** 1\
**Showing post:** 24

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [January 23, 2023, 2:03pm UTC](https://discourse.julialang.org/t/getting-different-result-from-serial-and-multithreaded-code-in-julia/93257/24 "2023-01-23T14:03:36Z")

</div>

> [@DNF](#):
>
> This was a real surprise. Is this something new?

The suggestion to avoid that patterns is old as pointed in FLoops docs, but what’s new is that, AFAIU, since 1.7 the tasks can effectively migrate: [Julia 1.7 says it can switch the thread your task is on. How often does that happen, and how can it be disabled?](https://discourse.julialang.org/t/julia-1-7-says-it-can-switch-the-thread-your-task-is-on-how-often-does-that-happen-and-how-can-it-be-disabled/75373)

I don’t know of any drop in replacement other than executing the threaded loop at a higher level, defining a chunk index independent of the thread (which is what I do in the ChunkSplitters.jl package I mentioned above, and which I’m using to avoid this in simple parallel loops like this one).

---

_[View the full topic](https://discourse.julialang.org/t/getting-different-result-from-serial-and-multithreaded-code-in-julia/93257)._
