Multithreading with BACI

BACI, both sources and compiled binaries for different platforms, can be downloaded here.

It should be installed on faculty computers and is installed on lts.wmi.amu.edu.pl.

Tasks

Task 1. Run the sample programs from the 11th lecture, find an ordering of instructions in different threads which shows that only the Petereson’s algorthm nicel solves the critical section problem.

Task 2. Write a program with 9 threads that concurrently increment a single variable (no synchronization). Observe that the final value is different to the one you might expect and can differe between runs.

Task 3. Synchronize the work between 9 threads using an atomic function.

Task 4. Implement a mutex in BACI using a binary semaphore. Use it to synchronize the work between 9 threads.

Task 5. Implement a mutex in BACI using atomic functions. Use it to synchronize the work between 9 threads.

Task 6. Try to implement in BACI the Lamport’s bakery algorthm which gives a solution to the critical section problem for more than two threads.