Write a program that creates 1,000,000 random integers 0-9. It should then create two threads, which iterate over % of the integers, summing them using a single global variable. When both threads...


in c programming


Write a program that creates 1,000,000 random integers 0-9. It should then create<br>two threads, which iterate over % of the integers, summing them using a single<br>global variable. When both threads complete, the main thread should print the sum,<br>then sum the array itself and print the correct value.<br>In the threads, wrap the access to the single global variable with a semaphore.<br>Rerun.<br>Change the threads to use a local variable for summing, and then update the global<br>with the semaphore lock. Rerun.<br>Hints:<br>Don't forget to compile with -Ipthread<br>Make your semaphore global, your pthread structures local.<br>

Extracted text: Write a program that creates 1,000,000 random integers 0-9. It should then create two threads, which iterate over % of the integers, summing them using a single global variable. When both threads complete, the main thread should print the sum, then sum the array itself and print the correct value. In the threads, wrap the access to the single global variable with a semaphore. Rerun. Change the threads to use a local variable for summing, and then update the global with the semaphore lock. Rerun. Hints: Don't forget to compile with -Ipthread Make your semaphore global, your pthread structures local.

Jun 11, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here