Constants are gcsafe, and vars are not for “obvious reasons”. I am currently doubting my understanding of nim threads and gcsafe. I first believed by the naming and whatnot that locks stopped a thread to make sure it was the only one that could access a global var, which suggests this is an issue with simultaneous editing from different threads. What I got from these recent tests is that threads all have different memory, which is why you can’t access vars and procs across threads. Then what do locks do? How do they bypass this? Should I use locks for let access, or just force it to be gcsafe using {.gcsafe.}:, and how does the force work anyway, if they have different memories?
Example:
const a = "hello"
proc foo() {.gcsafe.} =
echo a
let b = "hello"
proc bar() {.gcsafe.} =
echo b
TLDR: Are the gcsafe issues based off the fact that threads have separate memories or timing issues? If they have separate memories, how can they still access the main threads variables through locks and force. Is it unsafe to access let var’s using a forced gcsafe from inside a thread?