Question: Problem 8 . ( 6 points ) : Processes vs . threads. This problem tests your understanding of the some of the important differences between
Problem points:
Processes vs threads. This problem tests your understanding of the some of the important differences
between processes and threads. Consider the following program:
#include "csapp.h
int main
Global variables
int cnt;
semt mutex;
int ;
pthreadt tid;
seminit&mutex, ; mutex
Helper function
void incr void vargp
P &mutex ;
cnt;
&mutex;
return NULL;
Processes
;
for
incr NULL ;
if fork
incr NULL ;
exit;
for ;;
waitNULL ;
printfProcs: cnt
cnt ;
Threads
;
for
incr NULL;
pthreadcreate&tidi NULL, incr, NULL;
for ;;
pthreadjointidi NULL ;
printfThreads: cnt
;
exit;
A What is the output of this program?
Procs:
Threads: nt
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
