Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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 usageStep 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