In computer science the term "critical section" refers to a section of code for which is not safe to allow muliple processes to concurrently execute, either by time-sharing a single processor or by true simultaneous execution on a multiprocessor system. Such "critical sections" must be protected against concurrent execution by some type of locking mechanism, either a mutex or a spin lock usually, but sometimes by clever coding alone with no locking at all. For example, a concurrently accessible queue or stack may be coded by taking advantage of a special atomic processor instruction that perform a test and increment operation in a single instruction (e.g. the Compaq (nee Digital) Alpha processor has such an instruction), and no locking is required because the critical section has essentially been reduced in length to a single, atomic processor instruction.

What is missing above is, why critical sections are called "critical". In a critical section either shared data or the hardware is accessed (since the hardware exists only once, it could be seen as 'shared data' also). Concurrent access to shared data might loose updates or damage the administrative structures (just imagine two threads adding a new frontmost node to a double-linked list at the same time). Concurrent access to hardware may result in intermingled commands,
violation of timing constraints and other nice things
leading to crashes. How to handle critical sections is explained above.

Log in or register to write something here or to contact authors.