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.
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 123Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started