Reference no: EM131092565
Operating Systems Assignment-
Question 1 - Using pthreads, add multi-threading to the server in the sample solution for assignment 1 question 2. The server will use a thread pool (as discussed in class) to support the handling of multiple concurrent requests. In other words, you will have a thread (main) that's doing a blocking read on the FIFO and will hand off each message to a worker thread for processing.
Note that to terminate all of the worker threads, the main thread will need to provide the threads with data (such as a -1) to indicate that it is time for the threads to finish. Further, the main thread must ensure that all worker threads are done before it terminates the server.
Be careful with what needs to be protected! All shared resources are subject to access by multiple threads. This includes shared (file scope) variables and any file handles (you never know which threads may access the same file). But, to make things a little simpler, remove support for the HUP signal. That way we can treat the template as read only and free from any protection issues.
The number of worker threads can have a noticeable effect on throughput. Experiment with having thread counts that are less than and greater than the number of clients. How many worker threads do you need? Do you need more than the maximum number of clients? The same number? Will less do? Why? Include your answer (in the form of a paragraph) in your assignment's readme file.
Finally, note that all you need to hand in is server.c. The marker will be using the rest of the assignment 1 sample solution to test your solution.
Question 2 - Using pthreads, implement a bounded buffer. Use condition variables for full and empty and a lock on the entire buffer (and our condition variables). Each producer will take the string "Now is the time for all good people to come to the aid of their country" and write it to the shared buffer, one character at a time. Your consumer will read a character from the buffer and write it to standard output (one at a time). Be careful: the consumer must finish when all of the producers are done. How can the consumer know when a producer is finished?
To test a variety of configurations, vary the buffer size between 2 and 128, incrementing by powers of 2. For each of these sizes, vary the number of producer threads between 2 and 128, incrementing by powers of 2. Note that you'll need to wait for all threads to finish before starting the next round. In your readme, include a paragraph discussing how the output changes as you vary the buffer size and number of producers. Run your program a number of times. How does the output change?
Attachment:- Assignment.zip