This lab will give you a introduction in the basic concepts of concurrency. You will create two processes (these are called tasks in Tornado) which will both operate on shared memory. More specifically, these two tasks will 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. This idea is known as mutual exclusion. The region of code which requires mutual exclusion is known as a critical region. If mutual exclusion is not provided to a critical region, the outcome of the program can be incorrect. Note that the output might not always be incorrect because of the exact scheduling of the two tasks. This idea makes it difficult to prove the correctness of any concurrent program.
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.
In this lab, you will need to:
1. Create a new project in Tornado.