What is the correct way in C to make sure that when one thread writes to a variable the other thread can read the updated value? I didn't find any answers to this despite searching and 'Questions that may already have your answer', which gave me results that weren't C, and there were a lot of them.
As far as I can tell it isn't covered in C so I would have to rely on platform specific calls but I am looking for something portable across platforms. I know I can use a lock but I think that would have some unnecessary overhead since I'm sure that one thread only needs to read from the variable and the other thread only needs to write to the variable. I want the thread reading the variable to know as soon as it was modified. Is there a correct not platform specific way to do that? Thanks