[armedbear-devel] [RFC] Support for 'synchronized' blocks in Lisp code
Anton Vodonosov
avodonosov at gmail.com
Tue Jul 7 21:36:11 UTC 2009
Note, btw, that "synchronized" in java is not only about locking, but
also about memory synchronization: the code in the synchronized block
is compiled so that other threads see the changes it has made to
memory and it sees changes from other threads too. Compiler doesn't
cache values in registers or other temporary places.
Example:
(let ((zu 0)
(monitor "just a string"))
(defun set-zu (val)
(synchonized (monitor)
(setf zu val)))
(defun print-zu ()
(dotimes (i 10)
(synchonized (monitor)
(format t "zu: ~A~%" zu)))))
If we want to preserve java "synchronized" semantics, when compiling
PRINT-ZU the compiler should not read ZU value only once, cache it in
some local variable, and the use this local to as an argument to
FORMAT in DOTIMES.
Not sure whether this requirement complicates "synchronized"
implementation for ABCL.
Best regards,
- Anton
More information about the armedbear-devel
mailing list