Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started