Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The program shown below uses the Pthreads API. Run the program and find out what the output are at LINE C and LINE P. Add

The program shown below uses the Pthreads API. Run the program and find out what the output are at LINE C and LINE P.

student submitted image, transcription available below

Add a second thread to the program above replicating the child process part for the new thread. Execute your code three times and record the output and explain why you get those results.
 

#include #include int value = 0; void *runner (void *param); /* the thread */ int main(int argc, char *argv[]) { pid_t pid; pthread_t tid; pthread_attr_t attr; pid = fork(); if (pid == 0) { /* child process */ pthread_attr_init(&attr); pthread create(&tid, &attr, runner,NULL); } else if (pid gt; 0) { /* parent process */ wait (NULL); printf("PARENT: value = %d", value); /* LINE P */ } pthread_join(tid, NULL); printf("CHILD: value = %d", value); /* LINE C */ } } void *runner (void *param) { value= 5; pthread_exit(0);

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Now lets explain the code and predict the output 1 The program creates a shared variab... 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 Operating System questions

Question

Was MGRM hedging or speculating? LO6

Answered: 1 week ago