0
0
Operating Systemsknowledge~10 mins

Semaphores (counting and binary) in Operating Systems - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a binary semaphore initialized to 1.

Operating Systems
binary_semaphore = Semaphore([1])
Drag options to blanks, or click blank then click option'
A2
B0
C1
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Initializing binary semaphore to 0 causes immediate blocking.
Using negative values is invalid for semaphore initialization.
2fill in blank
medium

Complete the code to initialize a counting semaphore with 5 available resources.

Operating Systems
counting_semaphore = Semaphore([1])
Drag options to blanks, or click blank then click option'
A5
B0
C1
D-5
Attempts:
3 left
💡 Hint
Common Mistakes
Initializing counting semaphore to 0 blocks all threads initially.
Negative initialization values are invalid.
3fill in blank
hard

Fix the error in the code to correctly wait (P operation) on a semaphore.

Operating Systems
semaphore.[1]()
Drag options to blanks, or click blank then click option'
Asignal
Bwait
Crelease
Dpost
Attempts:
3 left
💡 Hint
Common Mistakes
Using signal() or post() instead of wait() causes incorrect semaphore behavior.
Confusing wait() with release() method.
4fill in blank
hard

Fill both blanks to correctly signal (V operation) a semaphore and update the resource count.

Operating Systems
semaphore.[1]()
resource_count [2] 1
Drag options to blanks, or click blank then click option'
Asignal
B+=
C-=
Dwait
Attempts:
3 left
💡 Hint
Common Mistakes
Using wait() instead of signal() causes deadlock.
Decreasing resource count after signaling is incorrect.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps resource names to their availability status using a binary semaphore.

Operating Systems
availability = [1]: semaphore.[2]() == 1 for [3] in resources
Drag options to blanks, or click blank then click option'
A{resource
Bwait
Cresource
D[resource
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets instead of curly braces creates a list, not a dictionary.
Using signal() instead of wait() changes semaphore state incorrectly.