Please note that the content of this book primarily consists of articles
available from Wikipedia or other free sources online. In concurrent
programming a critical section is a piece of code that accesses a shared
resource 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. 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, 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.