[Openmcl-devel] Is setf atomic?
Pascal Costanza
pc at p-cos.net
Tue Nov 6 13:07:53 PST 2007
On 6 Nov 2007, at 21:59, Andrew Shalit wrote:
> What would it mean for (setf var 42) to be thread-safe or not thread
> safe?
>
> I can understand what this might mean for
>
> (setf var (do-something-complex)) ;; lots of stuff can happen
> during the calculation of do-something-complex
> ;;and
> between the time that value is calculated and the variable is assigned
>
> and I can understand what it could mean for
>
> (progn
> (setf var 42)
> var) ;;var might not be 42 at this point
>
> or
>
> (progn
> (setf var 42)
> (setf foo var)) ;; foo could be set to pretty much anything
>
> But what would it mean for (setf var 42) in isolation not to be
> thread safe?
42 could be stored in a 64-bit place, and the store operation could be
split up in two 32-bit store operations. Thus, it could happen that
other threads see just garbage when they happen to do a read access in
between.
For example, that's a case that is documented for Java's memory model,
see http://java.sun.com/docs/books/jls/third_edition/html/memory.html#17.7
Pascal
--
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
mailing list