Complete the code to declare a binary semaphore initialized to 1.
binary_semaphore = Semaphore([1])A binary semaphore is initialized to 1 to indicate that the resource is available.
Complete the code to initialize a counting semaphore with 5 available resources.
counting_semaphore = Semaphore([1])A counting semaphore initialized to 5 means 5 resources are available for concurrent access.
Fix the error in the code to correctly wait (P operation) on a semaphore.
semaphore.[1]()The wait() method is used to decrement the semaphore and block if the resource is unavailable.
Fill both blanks to correctly signal (V operation) a semaphore and update the resource count.
semaphore.[1]() resource_count [2] 1
The signal() method releases the semaphore, and the resource count increases by 1.
Fill all three blanks to create a dictionary comprehension that maps resource names to their availability status using a binary semaphore.
availability = [1]: semaphore.[2]() == 1 for [3] in resources
This dictionary comprehension checks if each resource is available by waiting on its semaphore and maps the resource name to a boolean.