
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Main points of this documents are: Multithreaded, Bubble, Merge, Sort, Numbers, Variables, Semaphores, Temporary, Files.
Typology: Exercises
1 / 1
This page cannot be seen from the preview
Don't miss anything!

Q1: Write a program that implements a multithreaded bubble— merge sort. Have the initial process generate 10,000 random numbers—writing the numbers in groups of 1,000 each to 10 separate temporary files. Then create 10 threads and pass each a reference to one of the temporary files and a common bubble-sorting routine. As each thread finishes, its sorted results should be returned to the initial thread that performs a merge of sorted results (i.e., the temporary 1,000 number file) with a final, fully sorted file. Where appropriate, use semaphores and/or mutexes or condition variables to coordinate activities. Run your solution several times to be sure it works correctly. Once all the data is ordered, display every 100th value in the final data set to attempt to establish if the data was truly sorted. All temporary files and other data structures should be removed once processing is complete.
Your program will take two command-line arguments: the number of values to sort and the number of files