Question
Run the following C program (tprog2.c) and observe the result on the screen. Briefly explain why we may get the interleaving messages from the se
Run the following
C program
(tprog2.c) and observe the result on the screen.
Briefly
explain why we may get the interleaving messages from
the
se
two processes.
#include
#include
#include
#include
void* print_i(void *ptr)
{
printf("1: I am
\
n");
sleep(1);
printf("in i
\
n");
}
void* print_j(void *ptr)
{
printf("2: I am
\
n");
sleep(1);
printf("in j
\
n");
}
int main()
{
pthread_t t1,t2;
int rc1 = pthread_create(&t1, NULL, print_i, NULL);
int rc2 = pthread_create(&t2, NULL, print_j, NULL);
exit(0);
}
3.
Add mutex lock
s
to tprog2.c
to achieve synchronization,
and
then
observe the result on your
screen.
Submit the following on Blackboard:
1) a text file (e.g. q2.txt) that includes your answer to question 2.
2.Add mutex locks to tprog2.c to achieve synchronization,and then observe the result on your screen.
3. a screenshot of running tprog3
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