Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ASAP Please read the requirements and answer accordingly. Please need it as screenshots of the code and commands to run it. I'll give thumbs up.

ASAP Please read the requirements and answer accordingly. Please need it as screenshots of the code and commands to run it. I'll give thumbs up.
image text in transcribed
You are required to create a child thread from a parent thread which is expected to populate an integer array which is then displayed by the parent thread. The program is expected to take a number from the command line arguments which indicates the number of elements to be added to an integer array starting from to that number (exclusive). example, if 10 is provided from the command line arguments, it means that array should have numbers fron to 9 (total of 10 numbers). Below are the responsibilities of both Parent and the Child threads: Parent Thread: This thread is responsible for - Displaying its thread ID - Creating a child thread and passing it the number of elements to be added to the array received through command line arguments along with a function which would run for the child thread - Joining the threads - Finally, displaying all the elements inserted in the integer array Child Thread: This thread is responsible for - Displaying its thread ID - Creating an integer array to store integer values (size is received from the parent thread which basically is the only command line argument passed) - Returning the integer array to the parent thread so that parent thread can display the elements of this array - Finally, exiting the thread Note the following: - You need to create a separate function that would run in the child thread. - You might want to look into malloc function in C that helps in creating dynaanic arrays in C. For example, below is the line of code you can use to create a dynamic array in the heap memory: int * numbers = malloc ( size sizeof ( int )); - Do not forget to release the memory allocated to dynamic array by using free function. For example, below is the line of code you can use to release the memory occupied using ma1loc (result is a pointer pointing to that dynamic memory in the main method returned by thread function): free( result); - Do not use global variables. Hint: use malloc in the function created for the child thread and free in the main function

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

Students also viewed these Databases questions

Question

Discuss the states of accounting

Answered: 1 week ago