Question 41
MediumIn Java, what do wait() and notify() do inside a synchronized block?
- A.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Operating Systems
In Java, what do wait() and notify() do inside a synchronized block?
Both release the lock permanently
They are used for file I/O
wait() kills a thread; notify() starts it
wait() releases the lock and pauses the thread; notify() wakes one waiting thread
Sign up free to see the answer and a step-by-step explanation.
In the second readers–writers problem, who gets priority, and who may starve?
Readers get priority; writers may starve
Both always starve
Writers get priority; readers may starve
Nobody can starve
Sign up free to see the answer and a step-by-step explanation.
Which change prevents deadlock in the dining philosophers problem?
Let one philosopher pick up the right chopstick first while the others pick up the left first
Remove the table
Give each philosopher three chopsticks
Make all philosophers pick up the left chopstick first
Sign up free to see the answer and a step-by-step explanation.
What does a compare-and-swap (CAS) instruction do?
Compares two files
Swaps two processes
Atomically sets a variable to a new value only if it still holds an expected old value
Sorts an array
Sign up free to see the answer and a step-by-step explanation.
What is a lock-free data structure?
One that is read-only
One that has no data
One whose operations use atomic instructions like CAS instead of locks, so a stalled thread can't block others
One stored on disk
Sign up free to see the answer and a step-by-step explanation.
What is barrier synchronisation?
A method for stopping deadlocks
A lock that only one thread can hold
Threads wait at a point until all of them have arrived, then continue together
A wall between processes' memory
Sign up free to see the answer and a step-by-step explanation.
What is a reentrant (recursive) lock?
A lock used only for files
A lock that the thread already holding it can acquire again without deadlocking itself
A lock that can be held by many threads at once
A lock that unlocks itself after a time
Sign up free to see the answer and a step-by-step explanation.
What does a read–write lock allow?
Readers and writers together
Only one reader at a time
Many writers at once
Many readers at once, or a single writer
Sign up free to see the answer and a step-by-step explanation.
Why is briefly disabling interrupts acceptable for short critical sections inside the kernel of a single-processor system?
It works the same on multiprocessors
It allows more processes to run
It speeds up the CPU
No context switch can happen, so the section runs without interruption
Sign up free to see the answer and a step-by-step explanation.
What is the waiting queue of a semaphore used for?
Holding the processes blocked in wait() until a signal() releases them
Keeping the CPU's registers
Storing the semaphore's value
Listing all processes in the system
Sign up free to see the answer and a step-by-step explanation.