Jason Teagle wrote:
It definitely IS needed in that case... imagine if one thread was halfway
through writing the memory and hadn't finished updating memory - and then
another thread cut in and tried reading... it could get messy. The reading
thread might end up reading mismatched data, because only half of it had
finished being written at the time. Make sense?

Memory blocks need protecting just the same as variables - for the exact
same reasons - after all, a variable is just a small memory block.

There's only one exception to it, which is when the memory holds a variable which can be written with a single instruction (like a 4 byte integer) and you don't care if the reader thread gets an outdated value from time to time. In that case, I'd simply declare the variable as volatile, and access it as usual in the code.


All other cases need synchronization.

--
Ehsan Akhgari
Farda Technology <http://www.farda-tech.com/>

Time flies like an arrow. Fruit flies like a banana.

_______________________________________________
msvc mailing list
[email protected]
See http://beginthread.com/mailman/listinfo/msvc_beginthread.com for 
subscription changes, and list archive.

Reply via email to