Question 51
Mediumx starts at 0. Thread A runs x = x + 2 twice; thread B runs x = x × 2 once. Each statement is atomic, but the threads interleave in any order. Which final value is NOT possible?
- A.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Operating Systems
x starts at 0. Thread A runs x = x + 2 twice; thread B runs x = x × 2 once. Each statement is atomic, but the threads interleave in any order. Which final value is NOT possible?
8
4
6
2
Sign up free to see the answer and a step-by-step explanation.
Strict alternation (a single 'turn' variable that the processes take in turns) violates which requirement of a critical-section solution?
Bounded buffer
Mutual exclusion
Atomicity
Progress
Sign up free to see the answer and a step-by-step explanation.
What is a monitor in process synchronisation?
A type of semaphore value
A language construct that bundles shared data with procedures, allowing only one process inside at a time
A computer screen
A disk-scheduling method
Sign up free to see the answer and a step-by-step explanation.
What is busy waiting also called when used in a lock?
Spinning (a spinlock)
Paging
Blocking
Sleeping
Sign up free to see the answer and a step-by-step explanation.
In the first readers–writers problem (readers have priority), who can starve?
Readers
Both equally
Neither
Writers
Sign up free to see the answer and a step-by-step explanation.
x is a shared variable initialised to 0. Two threads each run x = x + 1 once (load, add, store) with no synchronisation. What can the final value of x be?
1 or 2
Only 1
0, 1 or 2
Only 2
Sign up free to see the answer and a step-by-step explanation.
Semaphore S starts at 0. P1 runs statement A and then signal(S); P2 runs wait(S) and then statement B. What does this guarantee?
B always executes before A
A and B never execute
A always executes before B
A and B execute at the same time
Sign up free to see the answer and a step-by-step explanation.
When is a spinlock a better choice than a blocking lock?
When the critical section does disk I/O
When the lock is held for several seconds
When the lock is held for a very short time on a multiprocessor
On a single-CPU system
Sign up free to see the answer and a step-by-step explanation.
What is priority inversion?
Two tasks swap priorities every time slice
A low-priority task always runs first
A high-priority task waits for a lock held by a low-priority task, which is itself preempted by a medium-priority task
The scheduler ignores priorities
Sign up free to see the answer and a step-by-step explanation.
Two threads update two shared counters. Thread 1 locks A then B; thread 2 locks B then A. What is the risk, and the usual fix?
A race condition; remove both locks
Starvation; use more threads
Deadlock; make both threads take the locks in the same order
Livelock; use a bigger time quantum
Sign up free to see the answer and a step-by-step explanation.