Question: SOCK MATCHING There are four threads that each make a random number of socks (1-100). Each sock thread produces a sock that is one of

SOCK MATCHING

There are four threads that each make a random number of socks (1-100). Each sock thread produces a sock that is one of four colors, Red, Green, Blue, Orange. The socks are then passed to a single matching thread. The matching thread finds two socks that are the same color. It then passes the pair of socks to the washer thread. The washer thread destroys the socks. In the console announce which thread is printing and what occurred: (Make sure your program ends. When there is no more work to finish it should terminate)

EXAMPLE OUTPUT

Red Sock: Produced 4 of 35 Red Socks

Green Sock: Produced 7 of 19 Green Socks

Matching Thread: Send Blue Socks to Washer. Total socks 234. Total inside queue 3

Washer Thread: Destroyed Blue socks

MATRIX MULTIPLICATION

Write a method matmult(float A, float B, float C, int m, int n, int p) that multiplies the m x n matrix A by the n x p matrix B to give the m x p matrix C. To make the program execute faster in a multiprocessor environment, use multiple threads to speed up the execution. Vary the number of threads using 1, 2, 4, 8. Also vary the size of the matrices above so that you can get a feel of how increasing threads will help to a limit.

EXAMPLE OUTPUT

Time with 1 thread: 15sec

Time with 2 thread: 8 sec

Then vary matrix sizeindicate size and print out times.

ORDERED LEADER ELECTION

Assume a system with N elected official threads and one rank thread. Each elected official has an identifying name and an integer rank value, where - is the lowest rank and + is the highest rank, use Random. Threads do not previously know the rank value of other threads. As threads are being created they should print out there name, rank and who they think is the leader, initially they think they are the leader, and notify the rank thread that a new elected official has been created, using an interrupt. When the rank thread is interrupted it will check the ranking of all the threads at the time and will only notify all threads if there is a new leader using an interrupt. The thread with the largest rank value is to be selected as the leader. You can use any algorithm that selects one and only one thread as the leader.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!