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.6 Atomic access to a cache in a hash table

Old:

(without-interrupts
 (or (gethash value *global-hashtable*)
     (setf (gethash value *global-hashtable*)
	   (make-cached-value))))

New: use the hash table lock.

(hcl:with-hash-table-locked 
 *global-hashtable*
 (or (gethash value *global-hashtable*)
     (setf (gethash value *global-hashtable*)
	   (make-cached-value))))

Alternative new: use the hash table lock only if the value is not already cached. This can be faster than the code above, because it avoids locking the hash table for concurrent reads.

(or (gethash value *global-hashtable*)	; probe without the lock
    (hcl:with-hash-table-locked
     *global-hashtable*
     (or (gethash value *global-hashtable*) ; reread with the lock
	 (setf (gethash value *global-hashtable*)
	       (make-cached-value)))))

LispWorks User Guide and Reference Manual - 21 Dec 2011

NextPrevUpTopContentsIndex