J
Jason Curl
I was reading a previous article about when to use volatiles.
My program has a shared memory buffer that is being accessed by two
threads. The threads are protected by an operating system specific means
(Windows Mutexes) so that I write using one thread and read using
another thread with it impossible to read and write at the same time.
So I read information from an external device using a thread (the time
it takes to do the read is dependent on that device and may be from
200ms to 30 seconds), while the other thread simply copies the
information into another buffer once per second and then operates on the
copy.
Now, the C question: is this portable if I write with one thread, and
only read "once" into a local variable in the other thread without
defining these buffers as being volatile?
I ask this so then the compiler may optimise some of the work it is doing.
My program has a shared memory buffer that is being accessed by two
threads. The threads are protected by an operating system specific means
(Windows Mutexes) so that I write using one thread and read using
another thread with it impossible to read and write at the same time.
So I read information from an external device using a thread (the time
it takes to do the read is dependent on that device and may be from
200ms to 30 seconds), while the other thread simply copies the
information into another buffer once per second and then operates on the
copy.
Now, the C question: is this portable if I write with one thread, and
only read "once" into a local variable in the other thread without
defining these buffers as being volatile?
I ask this so then the compiler may optimise some of the work it is doing.