# @async macro not recommended?

**URL:** https://discourse.julialang.org/t/async-macro-not-recommended/112404
**Category:** General Usage
**Created:** [April 2, 2024, 8:33am UTC](https://discourse.julialang.org/t/async-macro-not-recommended/112404 "2024-04-02T08:33:33Z")
**Posts on this page:** 1
**Showing post:** 6

<div class="post-metadata">

### Author: ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)
#### Post date: [April 3, 2024, 5:57am UTC](https://discourse.julialang.org/t/async-macro-not-recommended/112404/6 "2024-04-03T05:57:30Z")

</div>

Not really no as you have no guarantees where a Task pauses (AFAIK). It might be that in practice you will avoid some race conditions (e.g. if the compiler never inserts a yield into something like `array[i] += value` making it _practically_ an atomic operation). But I’d never want to rely on this! Julia has no way of controlling the yield points so you always had to guess where they are and hope - which is not how I would want to construct my programs 😅

To quote a [previous thread](https://discourse.julialang.org/t/is-async-memory-safe/66558/8):

> [@Is \`@async\` memory safe?](https://discourse.julialang.org/t/is-async-memory-safe/66558/8):
>
> The semantics of `@async` and `@spawn` tasks allow arbitrary interleaving of “pieces of code.” The only difference is that the granularity of the “pieces of code”. In `@async`, it’s the parts of the code delimited by the yield points (“I/O” operations). In `@spawn`, it’s individual machine instructions. So, this is why people tend to worry about the correctness of concurrent programs only when `@spawn` is used. More interleavings are possible and so it increases the possibility that bad things happen. However, since there is nothing in Julia language that makes sure certain function/method call does not contain a yield point [1], it is not correct to assume that manipulating a data structure from multiple `@async` tasks is safe, unless you read all the code reachable from the functions you are calling. (I guess it sounds rather like a FUD but I feel it is necessary for clarifying the current situation of concurrent programming in Julia.)

---

_[View the full topic](https://discourse.julialang.org/t/async-macro-not-recommended/112404)._
