What is Critical section?

Answer Posted / udipta bhuyan

In concurrent programming a critical section is a piece of
code that accesses a shared resource (data structure or
device) that must not be concurrently accessed by more than
one thread of execution. A critical section will usually
terminate in fixed time, and a thread, task or process will
have to wait a fixed time to enter it (aka bounded waiting).
Some synchronization mechanism is required at the entry and
exit of the critical section to ensure exclusive use, for
example a semaphore.

By carefully controlling which variables are modified inside
and outside the critical section (usually, by accessing
important state only from within), concurrent access to that
state is prevented. A critical section is typically used
when a multithreaded program must update multiple related
variables without a separate thread making conflicting
changes to that data. In a related situation, a critical
section may be used to ensure a shared resource, for example
a printer, can only be accessed by one process at a time.

How critical sections are implemented varies among operating
systems.

The simplest method is to prevent any change of processor
control inside the critical section. On uni-processor
systems, this can be done by disabling interrupts on entry
into the critical section, avoiding system calls that can
cause a context switch while inside the section and
restoring interrupts to their previous state on exit. Any
thread of execution entering any critical section anywhere
in the system will, with this implementation, prevent any
other thread, including an interrupt, from getting the CPU
and therefore from entering any other critical section or,
indeed, any code whatsoever, until the original thread
leaves its critical section.

Is This Answer Correct ?    11 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain the performance differences between user-space threads and kernel-supported threads.?

600


What is the working set of a process?

604


explain about the initial process sequence while the system boots up?

614


Explain the architectural differences between user-space threads, and kernel-supported threads?

513


How to work unix commands on windows xp without installing unix o/s in pc?

522






Explain what are the main families of threads?

572


Explain what are threads?

633


How would you kill a process?

632


Explain what is scheduling?

611


Explain how to work unix commands on windows xp without installing unix o/s in pc?

488


Tell me when should we use thread-safe "_r" library calls?

536


Explain similarities between thread and process?

588


What is the window of the working set of a process?

640


If your server is running on Unix and one of the sessions are keep on running without loading any data. how would you kill it?

627


What is protection boundary?

684