Using Tasks 101

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:

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 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.