Problem 1. The operation swap(r,m) atomically swaps the contents of register r and memory location m. Show how to use swap to implement a lock.
Problem 2. Show how we can use binary semaphores to coordinate 6 threads. Each thread has the following structure:
Thread(i) {
Code Section
}
Put binary semaphores around each thread's Code Section to implement the following scheduling constraints. T(i) ----> T(j) means that T(i) must completely finish its Code Section before T(j) starts its Code Section.
------->T2------->T4----- / \ | | | v T1 T5------->T6 | ^ | | \ / ----------->T3-----------
Problem 3 (Counts more). Santa Claus has two workshops. They are small, so no more than two elves can work in each workshop at any time. We'll refer to these workshops as H and L, where High-tech and Low-tech toys are made. There are four elves that make toys for Santa in these workshops. We'll call the elves G,D,T and J. The elves spend their time cycling between working and resting. At any time, a resting elf can come to Santa and ask to work in a particular workshop. We'll denote such a request by the procedure call Santa->start_work(elf,workshop). When an elf wishes to leave a workshop, he must ask Santa first. We'll denote this action by the call Santa->stop_work(elf,workshop). For each type of request, Santa can either grant the request or make the elf wait until the request can be granted.
Here are the rules that Santa has designed to ensure maximum productivity:
Show how to use locks and condition variables to implement Santa's workshop.