Question 31
MediumWhich semaphores does the classic bounded-buffer producer–consumer solution use?
- A.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Operating Systems
Which semaphores does the classic bounded-buffer producer–consumer solution use?
read and write
Only one binary semaphore
start and stop
empty, full and mutex
Sign up free to see the answer and a step-by-step explanation.
What does a monitor guarantee?
Only one process can be active inside the monitor at a time
Processes run in FCFS order
Memory is never shared
A process can never wait
Sign up free to see the answer and a step-by-step explanation.
Why is test-and-set useful for synchronisation?
It is faster than any other instruction
It disables the scheduler
It reads and sets a memory word in one atomic hardware instruction
It tests whether a program has bugs
Sign up free to see the answer and a step-by-step explanation.
In the classic dining philosophers problem, how can deadlock arise?
A philosopher eats too quickly
Philosophers take turns eating
There are more forks than philosophers
Every philosopher picks up their left fork at the same moment and waits for the right one
Sign up free to see the answer and a step-by-step explanation.
A counting semaphore starts at 3. The operations wait, wait, signal, wait, wait, wait are performed in that order. How many processes are blocked at the end?
0
1
2
3
Sign up free to see the answer and a step-by-step explanation.
In the producer–consumer solution with semaphores mutex, empty and full, what is mutex initialised to?
0
−1
1
The buffer size
Sign up free to see the answer and a step-by-step explanation.
Shared x = 5. Without any locking, one thread runs x = x + 1 and another runs x = x − 1 at the same time (each as load, change, store). Which final values of x are possible?
4, 5 or 6
Only 5
Only 4 or 6
Any integer
Sign up free to see the answer and a step-by-step explanation.
Why must wait() and signal() on a semaphore be atomic?
Otherwise two processes could both see the value 1 and both enter the critical section
To make them faster
Because semaphores are stored on disk
So that they can be interrupted safely
Sign up free to see the answer and a step-by-step explanation.
Which shared variables does Peterson's solution use?
A flag for each process and a turn variable
Two mutex locks
A counter and a queue
A single semaphore
Sign up free to see the answer and a step-by-step explanation.
What does the synchronized keyword provide in Java?
Garbage collection
Faster execution
Mutual exclusion using the object's built-in lock
Automatic parallelism
Sign up free to see the answer and a step-by-step explanation.