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.
(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))))