Discussion
Why do race conditions occur ?
(i) Values of memory locations replicated in registers during execution.
(ii) Content switches at arbitrary times during execution.
(iii) Threads can see stale memory values in registers.
Answer: D
All three are causes: (i), (ii) & (iii).
A race condition arises when the result of concurrent threads depends on the timing of their interleaving. Three facts combine to cause it:
- a thread copies a memory value into a register, works on it there and writes it back later (i);
- the scheduler can switch threads at arbitrary points, even between that read and that write (ii, where 'content switches' means context switches);
- so another thread can be working on a stale copy of the value in its registers, and one update overwrites the other (iii).
The classic example is two threads each executing count++ and the count rising by only 1. Any option leaving out one of these misses part of the mechanism.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development