Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The code that follows is a POSIX application that makes use of threads. How will the race problem be resolved if I modify the code

The code that follows is a POSIX application that makes use of threads. How will the race problem be resolved if I modify the code to pthread_join(thread[i], NULL) after the status check that is performed inside the for() loop?


Please explain provide proof. Thanks

image

#include #include #include #define NUMBER_OF_THREADS 10 void *print_hello_world(void *tid) { /* This function prints the thread's identifier and then exits. */ printf("Hello World. Greetings from thread %d ", tid); pthread_exit(NULL); } int main(int argc, char *argv[]) { /* The main program creates 10 threads and then exits. */ pthread_t threads[NUMBER_OF_THREADS]; int status, i; for (i=0; i < NUMBER_OF_THREADS; i++) { printf("Main here. Creating thread %d ", i); status = pthread_create(&threads[i], NULL, print_hello_world, (void *)i); } if (status != 0) { printf("Oops. pthread_create returned error code %d ", status); exit(-1); } exit(NULL);

Step by Step Solution

There are 3 Steps involved in it

Step: 1

In the given code the main program creates 10 threads using the pthreadcreate function If you modify ... 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

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions

Question

Statistical regression: Were extreme groups used?

Answered: 1 week ago

Question

Bonus shares can be issued out of revenue reserves. True/False?

Answered: 1 week ago