A critical section is a program segment
View worked solution
Answer: C
A critical section is a code segment in a multi-threaded or multi-process program where shared resources (such as shared variables, files, or hardware devices) are accessed.
To prevent data inconsistency and race conditions, only one process/thread is allowed to execute in its critical section at any given time (mutual exclusion).
Let's evaluate the options:
- Option A: There is no strict real-time constraint requiring a critical section to run in a specific amount of time, although it should be kept as short as possible to minimize waiting times for other processes.
- Option B: Critical sections do not inherently avoid deadlocks. In fact, improper synchronization around critical sections is a primary cause of deadlocks.
- Option C: This is the precise definition of a critical section.
- Option D: While semaphores ( and operations) are a popular synchronization tool, they are not mandatory. Other mechanisms like Mutexes, Monitors, Peterson's algorithm, or hardware instructions (like Test-and-Set) can also be used to protect critical sections.
Free practice · Your answers on this page are not saved.
