subject
Computers and Technology, 15.04.2020 23:10 goat561

Dining Philosopher Problem. There is a dining room containing a circular table with five chairs. At each chair is a plate, and between each plate is a single chopstick. In the middle of the table is a bowl of spaghetti. Near the room are five philosophers who spend most of their time thinking, but who occasionally get hungry and need to eat so they can think some more. In order to eat, a philosopher must sit at the table, pick up the two chopsticks to the left and right of a plate, then serve and eat the spaghetti on the plate. A philosopher may THINK indefinately. Every philosopher who EATs will eventually finish. Philosophers may PICKUP and PUTDOWN their chopsticks in either order, or nondeterministically, but these are atomic actions, and, of course, two philosophers cannot use a single CHOPSTICK at the same time. The problem is to 1 design a protocol to satisfy the liveness condition: any philosopher who tries to EAT, eventually does. Instructions. •

Task 1 (50 pts). Eliminate the deadlock by avoiding circular waiting. (Hint: change the order to access chopsticks for some philosophers.)

• Task 2 (50 pts). Eliminate the deadlock by avoiding hold and wait. In other words, if a philosopher is not able to obtain the right chopstick, he/she will release the left chopstick immediately. (Hint: Use Pthread Mutex to solve the problem.)

• Task 3 (50 pts extra credit). Eliminate the deadlock by limiting that at most 3 philosophers are able to compete for the chopsticks at the same time. (Hint: Use Pthread Conditional Variable to solve the problem.)

Skeleton Code: #include #include #include #include #include #define NUMP 5 pthread_mutex_t fork_mutex[NUMP]; int main(int argc, char* argv[]) { int i; pthread_t diner_thread[NUMP]; int dn[NUMP]; void *diner(); for (i=0;i

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 19:20
Number of megabytes of ram in a computer. qualitative or quantitative? because
Answers: 3
question
Computers and Technology, 21.06.2019 22:00
3. (6 pts) internally in the computer, with few exceptions, all numerical computation is done using binary numbers. output, however, often uses ascii, which is formed by appending 011 to the left of a bcd code. thus, an algorithm that directly converts a binary integer to a bcd integer is very useful. here is one such algorithm 1) draw lines to the left of the binary number to bound the expected bcd decades. (each decade is a group of 4 bits.) move the binary number one bit to the left. add 0011 to each bcd decade containing a binary value> 0100 repeat steps 2-3 until the last bit in the binary number has been moved into the least significant decade position. (note that when the last bit has been shifted into bcd decade, step 3 is not repeated.) read the bcd result. 2) 3) 4) 5) a) execute the algorithm for the binary number 1101101 b) execute the algorithm for the binary number 01110101110 4. (4 pts) represent the decimal number 3568 in bcd; excess-3 code; ascil; and hex.
Answers: 1
question
Computers and Technology, 22.06.2019 08:00
Someone with this coz i don’t really know what i can choose, just pick whatever u want. homework - you need to choose a website that you like or use frequently. you must visit the website and discuss 6 different features/parts/aspects of the website that you think makes it good. (100 words)
Answers: 2
question
Computers and Technology, 22.06.2019 19:20
How might the success of your campaign be affected if you haven’t carefully completed all field data or if you accidentally insert the wrong merge field in the document?
Answers: 2
You know the right answer?
Dining Philosopher Problem. There is a dining room containing a circular table with five chairs. At...
Questions