Critical Section

In any given system (that runs under a RTOS), there are resources that can be used by more than one thread; these are shared reources.  They can be variables, memory addresses, communication ports, registers, devices, etc.

Some shared resources can't be used by more than one thread at the same time. Not implementing a mechanism to serialize (one thread use the resource after another, and so on) the access to the shared resource will cause synchronization problems that may lead the system to some problems (most likely crash).

For implementing such synchronization mechanisms, it is neccesary to identify all the pieces of code in the different threads that try to access the shared resource. These pieces of code are known as critical sections.

We need to make sure that we avoid that two or more threads access the resource in a not serialized mode from their critical sections (inconsistent operation) at any point of time.