Your question is Thread-Safe Shared Resource Manager. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
CMT DriveWell services may share a bounded pool of reusable resources. Implement a thread-safe resource manager that allocates the smallest available resource identifier and safely returns resources to the pool.
The manager must support non-blocking acquisition. If no resource is available, acquisition returns -1. Releasing an unknown, already released, or out-of-range identifier returns False and must not change the pool.
Implement process_resource_operations(operations, capacity):
operations is a list of commands. An acquire command is ["acquire"]; a release command is ["release", resource_id].capacity is the number of resources, identified by integers from 0 through capacity - 1.-1. A release result is True or False.def process_resource_operations(operations, capacity):