D
Dave Stallard
Pardon if this is the wrong newsgroup for this question, and/or if this
question is naive.
I have a multi-threaded Windows application in which certain
variables/object fields are shared: one thread may write the variable,
and the other thread read it. The variables in question may have int or
int* types. Question: Is it safe to do this? Or is it possible a read
that happens at the same time as a write may retrieve a scrambled value,
in which, say, two of the bytes are from the old value and two of the
bytes from the new value?
In Java I know that such atomicity is guaranteed for ints, but not for
longs or doubles. So, perhaps I shouldn't assume it in a less
well-standardized environment
The application, btw, is a circular buffer with a read pointer and a
write pointer, which are moved forward by their respective threads. The
read thread needs to check to make sure that the read pointer is not on
the write pointer before reading. Using mutexes right now, but I worry
about their overhead...
Dave
question is naive.
I have a multi-threaded Windows application in which certain
variables/object fields are shared: one thread may write the variable,
and the other thread read it. The variables in question may have int or
int* types. Question: Is it safe to do this? Or is it possible a read
that happens at the same time as a write may retrieve a scrambled value,
in which, say, two of the bytes are from the old value and two of the
bytes from the new value?
In Java I know that such atomicity is guaranteed for ints, but not for
longs or doubles. So, perhaps I shouldn't assume it in a less
well-standardized environment
The application, btw, is a circular buffer with a read pointer and a
write pointer, which are moved forward by their respective threads. The
read thread needs to check to make sure that the read pointer is not on
the write pointer before reading. Using mutexes right now, but I worry
about their overhead...
Dave