EasyManua.ls Logo

ST ST7 - Page 40

ST ST7
317 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
40/317
2 - How does a typical microcontroller work?
process of updating the data, and another task uses that data, there is a risk of desynchroni-
zation. The same type of precautions must be taken to ensure atomicity of data updates. The
same problem may also occur if more than one task handles control sequences for an external
device. If this external device needs a precise control sequence that must be completed be-
fore a new sequence is started, there is a risk that a task may lose control before the sequence
is complete and control may be transferred to a task that attempts to use the same device. The
attempt may then fail or interfere with the unfinished sequence of the previous task. Here
again, a protection mechanism is required.
In summary, the advantage of pre-emptive multitasking is that task switching is done automat-
ically and independently from the code of each task; the relative power attributed to each task
maybeadjustedtofittherequirementsofeachtask.
The drawback is the opposite of the advantage: since the task switching happens at any time
and any place in the code, the programmer must locate the critical areas of code where spe-
cial protection mechanisms must be included. This may be more difficult than it might appear,
for it is not always easy to find all the possible collisions and keep them from happening.
02-preem
First task
Second task
Third task
Fourth task
Time
Preemptive multitasking
An allotted time
is assigned
to each task

Table of Contents

Related product manuals