The updated multithreading docs for v"1.5" says in section “Data-race freedom”:
Additionally, Julia is not memory safe in the presence of a data race. Be very careful about reading a global variable (or closure variable) if another thread might write to it! Instead, always use the lock pattern above when changing any data (such as assigning to a global) visible to multiple threads.
Thread 1: global b = false global a = rand() global b = true Thread 2: while !b; end bad(a) # it is NOT safe to access `a` here! Thread 3: while !@isdefined(a); end use(a) # it is NOT safe to access `a` here
It is not exactly clear to me, what this example tries to show. (two separated issues, or a single one?)
Are the following true?
- Removing thread 3 resolves the data race.
- If both
bad(a)only reads the value of
athen thread 2 is safe.
- I guess that
truebefore the random value is assigned to
a, so removing thread 2 does not resolve the race.
I plan to clarify the docs, but not sure if my understanding is correct. Thank you for helping!