# Using Tasks 101

**URL:** <https://discourse.julialang.org/t/using-tasks-101/114878>\
**Category:** Teaching & Outreach\
**Tags:** tutorials, task\
**Created:** [May 28, 2024, 9:31pm UTC](https://discourse.julialang.org/t/using-tasks-101/114878 "2024-05-28T21:31:45Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![Satvik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/satvik/32/20486_2.png) [@Satvik](https://discourse.julialang.org/u/Satvik)\
**Post date:** [July 21, 2024, 11:46pm UTC](https://discourse.julialang.org/t/using-tasks-101/114878/12 "2024-07-21T23:46:36Z")

</div>

> While `Channel` s are great for serializing access to shared resources like a common `Dict` , you could add a chapter about locks.

A post about this would be interesting for sure, but I’ve had a lot of trouble trying to write correct code with locks. E.g. we left code like this in our codebase for months, which was causing deadlocks in notebooks about once a week:

```julia
function setindex!(tsd::ThreadSafeDict, k, v)
    lock(tsd.slock)
    h = setindex!(tsd.d, k, v)
    unlock(tsd.slock)
    return h
end

```

In contrast when I wrote a Channel version of a thread-safe Dict it just worked.

> Your blog post says `@async` is deprecated? Julia’s official manual on [Network and Streams](https://docs.julialang.org/en/v1/manual/networking-and-streams/) uses `@async` in some examples. Should the examples be updated with `@spawn` as a drop-in replacement?

Probably? When I asked about it, I was told [“for new code there is no reason to use `@async`”](https://discourse.julialang.org/t/examples-of-when-to-use-async-over-spawn/114631).

---

_[View the full topic](https://discourse.julialang.org/t/using-tasks-101/114878)._
