Question: Please use thread to complete the following program: one process creates a thread my_thread . The job of the thread my_thread is to compute the

Please use thread to complete the following program: one process creates a thread my_thread. The job of the thread my_thread is to compute the sum of 1 to 100 (1+2++100), print out the result, and then terminate. The process waits for the termination of the thread, then terminate.

Basically, you need to implement main_process.c and thread_function.c.

Basic structure of main_process.c:

int main ()

{

Create a thread my_thread using pthread_create;

Wait until my_thread terminates, using pthread_join;

}

Basic structure of thread_function.c:

void *compute_sum()

{

Compute the sum from 1 to 100;

Print out the result;

}

For information about pthread_create and pthread_join:

man pthread_create

man pthread_join

How to compile and link your program:

gcc -o my_example main_process.c thread_function.c -lpthread

Please provide the accurate answer

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!