Question: 1. Write a java program that spawns n and m threads of two different types(classes) as described below, where n and m are program arguments.

 1. Write a java program that spawns n and m threads

1. Write a java program that spawns n and m threads of two different types(classes) as described below, where n and m are program arguments. These threads access a shared counter (initialized as 0 ) in a loop (50 000 iterations). In each iteration, the threads of the first type read the counter to a local (stack) variable, increment it, and store it back to the counter. The threads of the second type are performing the same set of operations but instead of incrementing the counter are decrementing it. When all threads finish, the program prints the value of the shared counter and the execution duration. (Try to check the value for equal number of incrementing and decrementing threads) Save the source to Lab3NoSync.java. 2. Modify this program using the keyword synchronized to protect the counter. The counter must be 0 at the end of the execution. Save your code to Lab3Sync.java. Run the 2 programs with equal sets of 1, 2, 4, 8, 16 and 32 threads and report the results as comments in your Lab3Sync file. Please report run time in ms, calculate the speedup (Lab3NoSync as reference) and your machine specification (processor specs and operating system)

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!