Question: C and Linux In this task, we create and deal with multiple threads. Write a program that gets an integer named numberOfThreads as its argument

C and Linux

C and Linux In this task, we create and deal with multiple

In this task, we create and deal with multiple threads. Write a program that gets an integer named "numberOfThreads" as its argument Use a for loop and create "numberOfThreads" new threads in the calling process. Define a function named "worker" that its return type and argument type are void* such that: It gets an integer named "threadNumber"; It prints "threadXumber" on the console; It uses a nested for loop to impose a high CPU load for a couple of seconds; It finds the square of "threadNumber' and stores in a global int array (say "squareNumbers") that keeps this value for all the threads; It prints a message that it is going to terminate the thread; terminates calling thread; This function should be invoked in the mentioned loop that creates new threads. Use a for loop and that waits for all the created threads to terminate. Print all the items in the array "squareNumbers" Run your program and also "top" (or "htop") at the same time and take a screen shot of your program's CPU usage

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!