[previous] [index] [next]

Example 7: RTL Semaphores

This example demonstrates two-process mutual exclusion of real-time tasks using semaphores.

Refer to the commented source code of the example for the details.

Principle of Operation

Running the Demo

To run the demo, change to the 'ex07_sem' subdirectory of the top-level tutorial directory, and run the 'run' script by typing
./run
Alternatively, change to the top-level tutorial directory and run the 'runall' script there by typing
./runall
and selecting the "Semaphores" button.

You'll see a window pop up with a log of diagnostics messages printing out. Look for the the results of the test, with and without semaphores, e.g.,

Sep  1 11:53:41 letti kernel: no sem: read/write/bad counts = 50753/538/47218
Sep  1 11:53:46 letti kernel: with sem: read/write/bad counts = 50665/537/0
The 'bad counts' signify times where the shared data was detected to be inconsistent. This should be 0 with the semaphore, and is likely to be nonzero without the semaphore.

See the Code


Next: Example 8, RC Airplane Servomotor Control

Back: Example 6, Shared Memory Communication