Question: i need help with my opearating system homework.The program must be implemented in linux. Multithread Programming In this project, you need to write a multithreaded
i need help with my opearating system homework.The program must be implemented in linux.
Multithread Programming
In this project, you need to write a multithreaded sorting program that works as follow:
A list of integers is divided into two smaller lists of equal size. You have to create two separate threads(sorting threads) to sort each sublist using the merge sort algorithm.
Then, the two sublists are merged into a single sorted list by a third thread(merging thread).
We will give yo a .txt file which contains several lines of integers as your input test data. Each line represents one test case which is composed by several numbers. So, you should figure out how to use argc, argv way to read in the test data line by line first.
Then, you need to implement the merge sort using multithreaded programming : two threads for sorting, and one for merging.
Make sure that the third thread(merging thread) get started after both sorting threads are done, which means you have to keep the merging thread waiting until the sorting threads finish their jobs by pthread condition wait.
Trace pthread.h first.
Finally, you should print out your running time for each test case on the screen, and output a .txt file for your sorting result.
The output filename must be output.txt.
Please output your result with the same format as the input we gave you.
We will use more difficult test cases to test your program.
At most 10000 integers for one test case.
You can find some test cases to test your program by yourself.
You should implement under Linux.
Only merge sort is acceptable.
Must use argc, argv way to input the test file.
Use gcc hw2.c pthread o hw2.o to compile your code.
Your command to run and output your code must be ./hw2.o testcase.txt output.txt
test case file info
-16342 2084 -10049 10117 2786
-659 -4905 12975 10579 8081 -10678 11762 6898 444 -6422
-15892 -13388 -4441 -11556 -10947 16008 -1779 -12481 -16230 -16091 -4001 1038 2333 3335 3512 -10936 5343 -1612 -4845 -14514
3529 9284 9916 652 -6489 12320 7428 14939 13950 1290 -11719 -1242 -8672 11870 -9515 9164 11261 16279 16374 3654 -3524 -7660 -6642 11146 -15605 -4067 -13348 5807 -14541 -16095 13723 -7343 -7441 2881 6265 11063 7422 -493 -9654 7987 -1033 -1377 14718 8010 -12835 3246 -3760 7701 3571 2373
-4543 -11417 -9007 -2452 9925 561 16056 8243 -5060 -10846 5155 -265 -14301 6546 158 -11550 14732 -11744 13275 6321 -6453 -2406 -14077 15290 6003 -11362 12362 10541 2689 -10113 -10554 10394 -810 -11286 129 7603 -3093 -7222 2253 5972 8384 7272 -809 -12352 -4331 10967 -15233 558 5341 -2417 -12953 14724 13808 1624 -5046 -926 -4096 11370 -6000 -1438 -7474 15826 -6625 7838 2205 -9961 8563 11123 -3353 30 12785 -15483 16208 2379 -14728 1027 -10024 11241 4154 5165 -9900 11212 -12342 -12781 7967 -6092 14453 -7009 -5363 -11787 7638 10965 6816 3285 8101 -8102 -11649 -16330 -14384 10035
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
