Subj : Re: deadlock avoidance To : comp.programming.threads From : robertwessel2 Date : Thu Jul 07 2005 01:45 am Satendra wrote: > Hi Jose, > I guess my statement was misinterpreted. What i meant by atomic here > is that if we have lets say an integer i with initial value 0 .Thread > T1 unconditionally modified to 2 (i = 2) then T2 at any time will read > it as either 0 or 2 but nothing in between, I agree that with c++ > objects this might not be true. I still don't understand why a function > who is just checking/reading the value of a global variable can't be > reentrant ? Consider an implementation of C on an eight-bit microprocessor where ints are 16 bits. And the assignment is x=513 (with an original value of zero). The generated code will clearly have to temporarily leave x in a state where if it were read, would be 512 or 1. And on many architectures, non-aligned accesses have little, if any, guarantee as to atomicity, particularly in the presence of multiple processors. If you use sig_atomic_t, that will generally* be safe to access as a unit. On an eight-bit processor, sig_atomic_t will likely be a char. *The C standard doesn't actually define sig_atomic_t to have any particular performance with respect to threads, but most thread-aware C implementations do what you'd expect. .