Programming Assignment 2: Implementation of Semaphore in Nios Environment
Due date: December 19th, 2007
The goal of this assignment is to provide race-free execution of four producer and four consumer threads.
Problem statement:
You will extend your programming assignment 1 so that the execution of your producer/consumer is race-free. To accomplish this task, you must first create your own semaphore type. Each semaphore must have its own blocking queue. Your semaphore mechanism will only be visible to all your threads. The up and down operation should also work as described in the book. Once you have created the semaphore type, you need to instantiate all the necessary semaphores so that all threads are synchronized and mutual exclusive. Here are a few interfaces that your semaphore type should have:
Hint: The NIOS processor does not have any compare and swap instruction. Thus, you have to provide atomicity by turning off the interrupt. Note that I do not want you to turn off interrupt for the entire critical section. Instead, you should strategically turn off interrupt when atomicity is needed to make your semaphore work correctly (e.g. update the semaphore value).
Submission procedure:
Grading Criteria:
Correctness: 70%
Readable and insightful comments: 20%
(hint: at the beginning, provide detailed information of the function. Information can be “what it does and how you build it?”)
Completeness of report: 10%