C++ Language/Std/Multithreading/Semaphores/ResourceManagement

Multiple threads might share a limited number of resources. Now, your code fragment isn't a critical section (multiple threads can now act simultaneously), but semaphore-based synchronization is needed to manage the resource pool using P() and V() functions that block a thread whenever all resources have been depleted.

Additional information about using a semaphore for resource management