[SOLVED] 代写 statistic 1. POSIX threads

30 $

File Name: 代写_statistic_1._POSIX_threads.zip
File Size: 310.86 KB

SKU: 4320438083 Category: Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Or Upload Your Assignment Here:


1. POSIX threads
CSE3321.3 Assignment 2.
Using Threads.
Due Date: Wed. July 10 4:00pm.
In all the following questions include a short answer and on which man page you found the information.
(1) What is the naming conventions for pthread function calls?
(2) Enumerate the synchronization mechanisms for POSIX threads?
(3) Why is it a good programming practice to call pthread_cond_wait from within a loop?
(4) Which thread executes after a thread is woken up from a condition variable.
(5) What happens if a thread blocks on a condition variable while holding two mutexes.
(6) What is a detached thread.
2. Dining Philosopher with Pthreads.
In this assignment you will write a pthreads program that evaluates some aspects of the pthreads system and prints some related statistics. In this pthread program the main program creates N [def. 5] threads that behave as philosophers. All of them immediately block on condition variable start_line. After all threads are created, the main thread wakes them up and then waits until the all of them have completed one cycle (or were blocked waiting for a chopstick or a chair). The main thread then collects some statistics and lets the philosopher run one more cycle for a total of T cycles [def. 100]. After the last cycle the main thread prints out the statics it collected and exits.
Every philosopher after waking from the condition variable start_line starts executing cycles. Each philosopher can be in one of three states: THINK, HUNGRY or EATING. If he is in THINK state he invokes a random number generator (which gener- ates numbers between 0 and 1 uniformly distributed) and compares the result with ¦Ë (lam) [def. 0.1]. If the random number is less than ¦Ë he switches to HUNGRY. If he is in HUNGRY state he will switch to EATING state when the chopsticks become available. And if the philosopher is in EATING state he invokes the random number generator and compares the result with ¦Ì (mu) [def. 0.2]. If the random number is less than ¦Ì he switches back to THINK state.
To avoid deadlock the philosophers limit the number of philosophers contending for the chopsticks to N-1 using a chair condition variable. You need one mutex to syn- chronize access to shared variables and blocking on condition variables.
1

The main thread at the end of every cycle collects the apropriate statistics and reports the following:
(1) Average Thinking Time. It does it by summing up the thinking time of all the philosophers and dividing by N. Average Hungry Time. It does it by summing up the hungry time of all the philosophers and dividing by N. Average Eating Time. It does it by summing up the eating time of all the philosophers and dividing by N.
Your program accepts optional arguments. The arguments can appear in any order and have to be one of the following:
-N N where N is the number of philosophers. -T T where T is the number of clock ticks. -LL where L is the ¦Ë.
-MM where M is the ¦Ì.
As always your program should be professionally written, with headers, comments, a Makefile, header files, etc.
2

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] 代写 statistic 1. POSIX threads
30 $