[Openmcl-devel] Is setf atomic?
gb at clozure.com
Tue Nov 6 18:53:36 EST 2007
On Wed, 7 Nov 2007, Pascal Costanza wrote:
> OK, I'll rephrase my question:
> Assume there is one thread executing the following endless loop on a shared
> global variable:
> (defvar *shared-var* 42)
> (loop (setf *shared-var* 84)
> (setf *shared-var* 42))
> Further assume that this is the only thread that ever assigns to *shared-var*
> - all other threads either don't touch it, or only read from it.
> Will the only values ever read from this variable be 42 and 84, or is it
> possible that sometimes some threads read something else (that is, garbage)
> from that variable?
Yes, the value will always be either 84 or 42 (barring hardware failure or
something like that); it will never have some of 42's bits and some of
I don't believe that any location that a lisp object could be stored in
could cross a page or cache-line boundary, but I'm fairly sure that this
would hold true in those cases as well. We may have a need to write
across cache-line/page boundaries in the IA32 port, but the only cases
where I can imagine this happening are like a tree falling in the forest
(other threads are suspended by the GC or the object being written
to is being initialized and isn't visible to other threads yet.)
> To generalize, are there datatypes other than integers for which it could be
> that other threads read garbage from such a variable?
Except for the case of trying to store 64-bit values into a foreign
data structure on a 32-bit machine, no.
> Thanks for your patience.
Likewise; sorry to have misunderstood.
> Pascal Costanza, mailto:pc at p-cos.net, http://p-cos.net
> Vrije Universiteit Brussel, Programming Technology Lab
> Pleinlaan 2, B-1050 Brussel, Belgium
More information about the Openmcl-devel