I’m working on adding multithreading support to our programming language (http://crystal-lang.org) and I’m facing an issue with thread local variables.
Since the language relies heavily on coroutines, basically the problem is that a function could start running on a thread, get suspended and continue running on a different thread.
So, for example, if I have this pseudocoe:
- read / write thread local variable
- do some context switch, might resume in a different thread
- read / write same thread local variable
Now the real issue is that when compiling with optimizations, LLVM wont re-read the thread local address, and instead it will rely on the address stored on some register.
The question is: is there any way to force LLVM to re-read the thread local address each time? Or even better, is there any way to give hints about where the cached address is not reliable anymore?