Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Visual C# And Databases

Authors: Philip Conrod, Lou Tylee

16th Edition

1951077083, 978-1951077082

More Books

Students also viewed these Databases questions

Question

The tree diagram can be used to _ _ _ _ _ _ _ _ _ _ .

Answered: 1 week ago

Question

Strong analytical, communication, and problem-solving skills

Answered: 1 week ago