On Wed, Nov 03, 2004 at 07:00:06AM +0200, Dvir Volk wrote: > Amit Aronovitch wrote: [snip] > 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? > what are the general rules this issue?
This isn't the problem - the problem is when one function of a library writes to a global variable, and another one reads it. If the library does not take threads into account, and expects the variable to keep its value, you might have a problem if two threads call the first function and then the second one. A very common example is errno, in libc. Read 'man 3 errno'. On older libc's it was a regular global veriable, and multi-threaded programs could not know for sure what caused the error in some library call, as another call from another thread might have wrote another value to it by the time you checked it. -- Didi ================================================================= 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]
