Question 1
Ten threads share an integer array that is initialized by main. Each thread when accessing the shared array has exclusive access. This means that no other thread in the group will be accessing it at that time. Hence, locking is not required. The threads agree to access the threads in sequence where the order of the sequence is determined by main. All the threads are released at the same time and may be executed by the scheduler in any order. However, they may only access the data in the sequence pre-determined by main. In effect this means that each thread must wait for earlier threads in the sequence to complete before accessing the data. There are three kinds of thread: TA adds x to each element in the array; TB decrements each element in the array and TC squares each element in the shared sequence. The number of each kind of thread is determined by main.
(Hint: Ask yourself how many Semaphores do I need?)
3 thread
Each thread do something different
Question 2
Re-write the dining philosophers using Semaphores to manage access to the shared resources. The problem of deadlocks can be solved by making one of the philosophers left handed. Use this approach to avoid deadlocking.
Hello
I can answer the questions as well as write the code for you. I really like Operating Systems and had the highest grade back at university on the OS class (not to mention I had completed multiple multithreaded/parallelized applications afterwards).