Académique Documents
Professionnel Documents
Culture Documents
Synchronization Techniques in
RTOSs
Explicit Implicit
flag counting
burst fifo
Real-time Embedded Systems- Lecture 03
Example
Consider a system comprising two tasks. One task samples a set of temperature data
from field sensors and another task computes the deviations from set values and switches
on or off the devices that cause heating/cooling (actuators).
timeframe
T1
Task T1 collects T2
data and stimulates
T2
Real-time Embedded Systems- Lecture 03
Advantages
This scheme ensures that T2 always processes the latest temperature data. Also it ensures
that the task T2 does not access the shared resource when T1 writes on it.
Disadvantages
Depend on how the cross stimulation is implemented. If it is blocking, i.e. T 2 waits for
the stimulation from T1, then the scheme has several problems:-
Using semaphores
set
reset
timeframe
T1 T2
Task T1 collects
Task T2 sets the semaphore
data
reads the data No access for T1 now
resets the semaphore
Task T1 sets the semaphore,
writes the data No access for T2 now
resets the semaphore
Real-time Embedded Systems- Lecture 03
} }
Task T1 blocks here Task T2 blocks here
Real-time Embedded Systems- Lecture 03
•The complexity of the problem increases with the number of shared resources.
•As a thumb rule, access to resources should be kept short. That is to say, the application
should block access to other tasks just when it is required, and release it as soon as the
job is over.
Let us suppose, we have 3 tasks, A, B and C which share a semaphore amongst them. The
priority sequence is A > B > C.
Let us suppose that C runs for some time, having set the semaphore, when it is pre-empted
by A
After having run for sometime, A tries to set the same semaphore and is blocked.
S
Real-time Embedded Systems- Lecture 03
Basic operation
Each set or increment will increase the COUNT by unity. When the COUNT reaches
MAX_COUNT, the task trying to set will block.
Each reset or decrement will decrease the COUNT by unity. When the COUNT reaches
zero, the task trying to reset will block.
We assume that the Scanner task writes data on to a buffer which is read by the Controller.
Thus the Scanner is the producer here and the Controller is the consumer.
Burst Mode: In this mode, if a number of tasks are in the blocked state waiting to set the
semaphore, the task with the highest priority gets unblocked first.
FIFO Mode: In this mode, if a number of tasks are in the blocked state waiting to set the
semaphore, they get unblocked in the sequence they posted a request for
set.
Real-time Embedded Systems- Lecture 03
s r
s
s
s r
s
s r
Basic operation
An Event Flag is a single byte or a two byte integer which is used to synchronize processes
particularly in a producer-consumer environment.
………………..
Semaphores and Event Flags may be used to share resources across processors
in a multi-processor environment. Such structures are located in the shared global
memory .
The usage is usually implementation specific with the following basic properties:
Semaphores (both flag and counting) are almost always in the FIFO mode.
Real-time Embedded Systems- Lecture 03
An Application has to create and initialize these structures before they are used by any
task. The OS provides the necessary system calls.
Usually, this is done by a startup task which starts first when the application starts and
then other tasks are started.