Lab 4 - Concurrency Issues
This lab will give you a introduction in the basic concepts of concurrency. Concurrency is a fundamental concept in embedded systems. Many systems include multiple processors or peripherals, with shard common resources. However, when tasks are split up and execute on seperate processors, a whole new class of problems arises.
Part 1 - Mutual Exclusion
One of the first problems that arises is that two or more tasks can access the same resource (e.g. memory location). This can lead to the situation in which there can exist multiple copies of the data with different values. In order to avoid this from happening, we need some sort of device that will limit access to resources to one process at a time. This is the concept behind mutual exclusion primitives such as locks and semaphores. The region of code or memory location that requires mutual exclusion is known as the critical region. If mutual exclusion is not provided or faulty, then the output of your programs would be incorrect.
In this portion of the lab, you will have two tasks which concurrently call the function increment(), which will handle incrementing a shared variable. Each task will call increment 10,000 times, therefore the final value of the shared variable should be 20,000. In order to implement this correctly, only one task should be allowed to update the shared variable at a time.
To provide mutual exclusion to the critical region (the increment function), you will need to use binary semaphores. These were used in the tutorial of lab 1 and can be found in the help files of Tornado. You will need the functions semBCreate, semGive, and semTake. For more information on semaphores, see the help files or look in your text book.
For part 1, you will need to:
Part 2 - Producer/Consumer Problem
In this section, you will be implementing the producer/consumer problem. This problem involves a bounded buffer which is modified concurrently by multiple processes. A producer adds items to the buffer and a consumer removes items from it. The buffer is bounded, therefore a producer can only add items when the buffer isn't full and a consumer can only remove items when the buffer isn't empty. In this lab, there will be exactly 1 producer and 1 consumer.
For part 2, you will need to:
Part 3 - Lab Report
In your lab report be sure to discuss the following: