in C Programming language ONLY(not C++ or java) (also write a short paragraph explaining how code works and includes sam

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

in C Programming language ONLY(not C++ or java) (also write a short paragraph explaining how code works and includes sam

Post by answerhappygod »

in C Programming language ONLY(not C++ or java) (also write a short paragraph explaining how code works and includes sample output) 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 (which we will term sorting threads) sort each sublist using a sorting algorithm of your choice. The two sublists are then merged by a third thread—a merging thread—which merges the two sublists into a single sorted list. Because global data are shared across all threads, perhaps the easiest way to set up the data is to create a global array. Each sorting thread will work on one half of this array. A second global array of the same size as the unsorted integer array will also be established. The merging thread will then merge the two sublists into this second array. Graphically, this program would look like this:
In C Programming Language Only Not C Or Java Also Write A Short Paragraph Explaining How Code Works And Includes Sam 1
In C Programming Language Only Not C Or Java Also Write A Short Paragraph Explaining How Code Works And Includes Sam 1 (13.59 KiB) Viewed 44 times
This programming project will require passing parameters to each of the sorting threads. In particular, it will be necessary to identify the starting index from which each thread is to begin sorting. The parent thread will output the sorted array once all sorting threads have exited. Here are the prototypes for the sorter and merger functions:
void *sorter(void *params);
void *merger(void *params);
Notice that for both functions, they have a single argument “void *params”. The pthread_create function takes in a routine (start_routine) (which would be the sorter or merger in this case) and an argument (arg) that may be passed to start_routine. In this case, it passes two values, the starting index of the sublist, and the ending index of the sublist. the *params value is of the type parameter and it is defined as so:
typedef struct
{ int from_index;
int to_index; }
parameters;
sorting threado 7,12, 19, 3, 18 original list 7, 12, 19, 3, 18, 4, 2, 6, 15,8 merge thread 2,3,4,6,7,8, 12, 15, 18, 19 sorted list sorting shread₁ 4, 2, 6, 15,8
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply