Dvir Volk <[EMAIL PROTECTED]> writes: > On a 1-CPU machine, when you have global variables such as ints or > floats, isn't reading and writing them atomic, and needs no locking?
Absolutely not! 1) It is not just reading and writing. Consider, say, incrementing a global variable. It involves a number of operations: fetch from memory into a register, add 1, write back into memory. If there is a context switch in between you are in trouble. 2) What if your memory bus has width less than the width of int? Even reads and writes will not be atomic. Now, how wide are your floats? > what are the general rules this issue? Serialize access to *all* shared data. -- Oleg Goldshmidt | [EMAIL PROTECTED] ================================================================= To unsubscribe, send mail to [EMAIL PROTECTED] with the word "unsubscribe" in the message body, e.g., run the command echo unsubscribe | mail [EMAIL PROTECTED]
