Question 71
HardIn a monitor, what happens when a thread calls wait() on a condition variable?
- A.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Operating Systems
In a monitor, what happens when a thread calls wait() on a condition variable?
It exits the program
It releases the monitor lock and sleeps until signalled
It keeps the lock and spins
It wakes all other threads
Sign up free to see the answer and a step-by-step explanation.
What is the main problem in the dining philosophers problem if every philosopher picks up the left fork first?
Starvation of only one philosopher
Philosophers eat too fast
Deadlock: everyone holds one fork and waits forever for the other
Forks are lost
Sign up free to see the answer and a step-by-step explanation.
Five philosophers share five forks. Why does allowing at most four of them to sit at the table at once prevent deadlock?
Four philosophers need no forks
With only four seated, at least one of them can always pick up both forks
It removes mutual exclusion
It forces them to eat in turn
Sign up free to see the answer and a step-by-step explanation.
In the second readers–writers problem (writers have priority), who may starve?
Readers
Only the first writer
Writers
Nobody
Sign up free to see the answer and a step-by-step explanation.
Two threads each run count++ 1,000 times without synchronisation, starting from 0. Which final value is possible?
Exactly 1,000 always
Any value from 2 up to 2,000
Only 0
Exactly 2,000 always
Sign up free to see the answer and a step-by-step explanation.
What is a deadlock-free way to lock two mutexes A and B in several threads?
Always lock them in the same global order, such as A before B
Lock them in random order
Lock B before A in half the threads
Never unlock them
Sign up free to see the answer and a step-by-step explanation.
What does an atomic compare-and-swap (CAS) do?
Locks the whole memory bus forever
Writes a new value only if the memory still holds the expected value, as one indivisible step
Swaps two registers
Compares two strings
Sign up free to see the answer and a step-by-step explanation.
What does a ticket lock add over a simple test-and-set spinlock?
It works without atomic instructions
It lets several threads hold the lock at once
First-come, first-served fairness: each thread takes a ticket number and waits for its turn
It never spins
Sign up free to see the answer and a step-by-step explanation.
A thread busy-waits on a spinlock held by another thread on the same single-core CPU. What is the problem?
Nothing; it is efficient
The CPU speeds up
The lock is released automatically
It wastes its whole time slice, since the lock holder can't run until it is pre-empted
Sign up free to see the answer and a step-by-step explanation.
What does priority inheritance solve?
Deadlock
Priority inversion: a low-priority lock holder temporarily gets the priority of a high-priority waiter
Thrashing
Starvation of low-priority tasks
Sign up free to see the answer and a step-by-step explanation.