> (defvar *val* 0)
>
> (run-thread (lambda () (setf * val* (1+ * val*)))
> (run-thread (labmda () (setf * val* (1+ * val*)))
>
> After the threads finish, *tmp* will be either 1 or 2 at the end of
> the execution, depending on whether the race conditions triggered.
>
>
> Instead you'd need, the following, which results in *val* always containing 2.
>
> (defvar * val* 0)
> (defvar *lock* (make-lock))
> (run-thread (lambda () (with-lock *lock* (setf * val* (1+ * val*))))
> (run-thread (lambda () (with-lock *lock* (setf * val* (1+ * val*))))
>
>
>
> If you just want an atomic counter, you could consider the function
> sb-ext:atomic-incf.
>
> BTW, the notation is a bit abstract, because I have my own wrappers
> for the SBCL and CCL multi-threading libraries and prefer to use said
> abstractions.
>
>
> On Mon, Oct 26, 2009 at 1:07 PM, Bhaskara Marthi
> <
bhaskara@willowgarage.com> wrote:
>> In other words, is it safe to have multiple threads reading a special
>> variable and/or using setq to change it, without any locking?
>> - Bhaskara
>>
>> --
>> Bhaskara Marthi
>> Research Scientist
>> Willow Garage Inc.
>> 650-475-2856
>>
>> ------------------------------------------------------------------------------
>> Come build with us! The BlackBerry(R) Developer Conference in SF, CA
>> is the only developer event you need to attend this year. Jumpstart your
>> developing skills, take BlackBerry mobile applications to market and stay
>> ahead of the curve. Join us from November 9 - 12, 2009. Register now!
>>
http://p.sf.net/sfu/devconference
>> _______________________________________________
>> Sbcl-help mailing list
>>
Sbcl-help@lists.sourceforge.net
>>
https://lists.sourceforge.net/lists/listinfo/sbcl-help
>>
>>
>