I think this should be done under the write lock, otherwise two concurrent calls to close might decrement the resource counter twice?