Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

It is required to implement the following using the “pthread” library in Linux.

ID: 3628503 • Letter: I

Question

It is required to implement the following using the “pthread” library in Linux. Do not
use Java threads.
(a) The main thread generates n pseudo-random integers, and stores them in an array.
It also reads an integer p, such that n is divisible by p.
(b) The whole array is logically divided into p segments with n/p elements in each.
The main thread spawns p child threads, where the ith thread will sort the ith
segment of the array.
(c) After all the child threads have finished their computation, the main thread will
merge the contents of the sorted array segments, and print the final sorted array.

Explanation / Answer

#include #include #include #include void *thread_function(void *arg); int *A; int main(){ int n,p,npar,i,j,k,start,end; int *B; int **arg; pthread_t *pt; printf("Enter 'n' value:"); scanf("%d",&n); do{ printf("Enter 'p' value such that p divides n :"); scanf("%d",&p); } while(n%p!=0); A=(int *)malloc(n*sizeof(int)); /*Creation of n random numbers*/ srand(time(NULL)); for(i=0;i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote