(without-interrupts
(or (gethash value *global-hashtable*)
(setf (gethash value *global-hashtable*)
(make-cached-value))))
(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)))))