curl https://www.labs.cs.uregina.ca/330/Threads/Lab5.zip -O -s unzip Lab5.zip
(Please do this lab on os1 or os2)
This week, we will be working with a countHeads function, which counts the number of 1's (representing heads) in an array of 1's and zeros. Your job is to convert the function from a regular function, written in C, to a threaded function. As a thread function, you will give it a portion of the array to work with, depending on the size of the array and the number of threads. Some of the code is provided for you already in main.c. You will notice that certain things are missing.
os1:~/cs330/Lab5$ ./demo How many threads? 10 How big is the array (100 elements or more)?135 0 0 1 1 0 0 1 1 0 0 0 1 0 0 1 1 0 0 1 1 0 1 1 0 0 0 0 1 1 1 0 1 1 1 1 0 0 0 1 0 0 1 0 0 1 1 1 0 1 0 1 1 1 1 1 1 1 1 0 1 1 1 0 0 0 1 0 0 1 0 1 1 1 1 1 1 0 0 1 1 0 0 0 1 1 1 0 1 0 1 0 1 0 0 0 0 0 0 1 1 0 0 1 0 1 0 1 1 1 0 0 1 0 0 1 0 1 1 1 1 0 1 1 0 1 1 1 1 1 0 1 0 0 0 0 Checking result: 72 Start:0 End:13 Start:13 End:26 Start:26 End:39 Start:39 End:52 Start:52 End:65 Start:65 End:78 Start:78 End:91 Start:91 End:104 Start:104 End:117 Start:117 End:135 The number of heads coin tosses is: 72 os1:~/cs330/Lab5$ ./demo How many threads? 5 How big is the array (100 elements or more)?100 0 0 1 0 0 0 1 1 1 1 0 1 0 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 0 1 0 0 1 1 1 0 1 0 1 0 1 1 0 1 1 0 0 0 0 1 0 1 1 1 1 0 1 1 0 1 0 1 0 1 0 1 1 0 1 0 0 1 1 0 0 0 1 1 1 1 0 1 1 1 0 0 1 0 1 1 1 1 0 1 1 1 0 0 1 0 Checking result: 54 Start:0 End:20 Start:20 End:40 Start:40 End:60 Start:60 End:80 Start:80 End:100 The number of heads coin tosses is: 54
Submit 3 files to URCourses: