If all processes are on the same machine, I'd create a file that contains the instance count. When the resource is provisioned by a process, the file should be opened for writing, effectively locking the file. The instance count should be read and incremented, then the write lock released on the file.
When a process exits (or is done with the resource), grab a write lock to the file and decrement the resource count. If the resource count is zero after the decrement, then initiate your cleanup procedure.
You will have to have retry logic in case a second process tries to grab a write lock on the shared file while the file is already open for writing by another process.
The important point is that the OS can give you an exclusive write lock, which is effectively your critical section.