Operating Systems - Semaphore vs Mutex - When to Use WhichWhat typically occurs if a thread tries to unlock a mutex that it has not previously locked?AThe system throws an error or undefined behavior occursBThe mutex is unlocked successfullyCThe thread is blocked until it acquires the mutexDThe mutex count is incrementedCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand mutex ownershipMutexes enforce ownership; only the locking thread can unlock.Step 2: Behavior on unlocking by non-ownerUnlocking by a non-owner usually causes an error or undefined behavior.Final Answer:Option A -> Option AQuick Check:Mutex ownership violation triggers error [OK]Quick Trick: Only owner thread can unlock mutex [OK]Common Mistakes:MISTAKESAssuming mutex unlock always succeedsConfusing mutex with semaphore behaviorThinking thread blocks on unlockTrap Explanation:PITFALLUnlocking by non-owner is not allowed, unlike semaphore postInterviewer Note:CONTEXTTests knowledge of mutex ownership and error handling
Master "Semaphore vs Mutex - When to Use Which" in Operating Systems2 interactive learning modes - each teaches the same concept differentlySolutionTrace
More Operating Systems Quizzes Banker's Algorithm - Safe State & Resource Allocation - Banker's Algorithm - Safe State & Resource Allocation - Quiz 6medium Critical Section Problem - Requirements & Peterson's Solution - Critical Section Problem - Requirements & Peterson's Solution - Quiz 6medium Disk Scheduling - SSTF, SCAN, C-SCAN - Disk Scheduling - SSTF, SCAN, C-SCAN - Quiz 7medium Internal vs External Fragmentation - Compaction & Buddy System - Internal vs External Fragmentation - Compaction & Buddy System - Quiz 13medium Page Replacement - FIFO, LRU, Optimal Algorithm - Page Replacement - FIFO, LRU, Optimal Algorithm - Quiz 4medium Process State Machine - Five-State Model - Process State Machine - Five-State Model - Quiz 11easy Process vs Thread - Key Differences - Process vs Thread - Key Differences - Quiz 5medium Round Robin Scheduling - Quantum & Turnaround Time - Round Robin Scheduling - Quantum & Turnaround Time - Quiz 8hard System Call - Mechanism & Modes (User vs Kernel) - System Call - Mechanism & Modes (User vs Kernel) - Quiz 14medium TLB - Translation Lookaside Buffer & Effective Access Time - TLB - Translation Lookaside Buffer & Effective Access Time - Quiz 13medium