Reads and writes an entry in a hash table atomically.
modify-hash hash-table key function => new-value, key
A hash table.
A function designator.
modify-hash locks the hash table hash-table. It then calls the function function with three arguments: key, the value currently associated with key in hash-table (if any), and a flag which is true if the key was in the table. (This last argument is needed in case the associated value is
modify-hash then sets the result of the function function as the value for key in the table.
modify-hash returns two values, the new-value and the key.
The overall effect is like:
(multiple-value-bind (value found-p)
(let ((new-value (funcall function
(setf (gethash key
(values new-value key
modify-hash should be more efficient.
It is guaranteed that no other thread can modify the value associated with key until
function is called with hash-table locked, so it should not do anything that may require hanging the modification, or that waits for another process that tries to modify the table.
LispWorks User Guide and Reference Manual - 20 Sep 2017