Question: Write a multithreaded sorting program that works as follows: A list of integers is divided into two smaller lists of equal size. Two separate threads,

Write a multithreaded sorting program that works as follows: A list of integers is divided into two smaller lists of equal size. Two separate threads, called sorting threads, sort each sublist using qsort a C library function. The two sublists are then merged by the first of the two threads into a single sorted list.

The data is set up as a global array. Each sorting thread will work on one half of this array. The merge thread will use a second global array of the same size as the unsorted integer array to merge the two sublists into this array. Write a multithreaded sorting program that works as follows: A list of

The main thread passes parameters to each of the sorting threads in a C struct. The parameters to be passed are the starting index and the number of items in each sublist.

The parent thread will output the sorted array once all threads have exited.

Unsorted data set:

int data[] = {7, 12, 19, 3, 18, 16, 4, 2, 6, 9, 18, 38, 15, 8, 123, 72, 4, 3, 11, 33, 15, 48, 13, 17, 23, 19, 30 ,45, 31, 1, 14, 50};

7 12 19 3 18 16 42 6 9 18 38 15 8 123 72 sorting thread To Ti sorting thread 7 12 19 3 18 16 4 2 6 9 18 38 15 8 123 72 Merge thread 2 3 4 67 8 9 12 15 16 18 18 19 38 72 123

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!