Dicts in different @async blocks

The question was if Dict is safe to use concurrent (but not parallel) tasks started via @async. Dict is obviously not “thread-safe” (“@spawn/@threads-safe”).

Though I agree that it’s a good idea to use a lock in this case anyway if you really need simultaneous access to Dict. (Even better and often much more efficient approach is to restructure your program so that you don’t need to use raw lock or atomics.)

No offense, but I believe this is a very dangerous attitude towards thread programming. In principle, you should be able to prove that that your program does not have data race given the public API definitions of the functions you are using. The behavior of your program is undefined otherwise. But I agree that documentation is lacking. Even basic thread programming constructs like Channel do not explicitly mention what operations are thread-safe in the docstring.

4 Likes