All Manuals > LispWorks User Guide and Reference Manual > 15 Multiprocessing > 15.2 The process programming interface > 15.2.6 Old interrupt blocking APIs removed

NextPrevUpTopContentsIndex

15.2.6.5 Atomic update of a data structure

The example below is a resource object, which maintains a count of free items and also list of them. These two slots must stay synchronized.

Old:

(without-interrupts
 (when (plusp (resource-free-item-count resource))
   (decf (resource-free-item-count resource))
   (pop (resource-free-items resource))))

New: use a lock, because more than one slot has to be updated, so cannot be updated with low level atomic operations.

(mp:with-lock ((resource-lock resource))
	      (when (plusp (resource-free-item-count resource))
		(decf (resource-free-item-count resource))
		(pop (resource-free-items resource))))

LispWorks User Guide and Reference Manual - 21 Dec 2011

NextPrevUpTopContentsIndex