Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

what is a C code that solves these problems? In the following questions, f 1 ( ) , f 2 ( ) , f 3

what is a C code that solves these problems?
In the following questions, f1(), f2(), f3() are thread functions. Use semaphores to obtain the result as requested in each equation.
The solution code MUST contain PThreads and Semaphores.
[1]
void *f1(void *arg)
{
printf(first);
}
void *f2(void *arg)
{
printf(Second);
}
void *f3(void *arg)
{
printf(Third);
}
The required result on screen monitor is
First
Second
Third
[2]
??* global variables*
int m=0;
int n=0;
void *f1(void *arg)
{
m =10;
}
void *f2(void *arg)
{
n =14;
}
void *f3(void *arg)
{
int r;
r = m + n;
printf(r =%d, r);
}
The required result on screen monitor is
r=24
[3]
int a =0;
int b =0;
int c =0;
void *f1(void *arg)
{
int r;
a =1;
r = a + b + c;
printf(r =%d, r);
}
void *f2(void *arg)
{
int r;
b =2;
r = a * b * c;
printf(r =%d, r);
}
void *f3(void *arg)
{
int r;
c =6;
r = c - a - b ;
printf(r =%d, r);
}
** The required result on screen monitor is
r=9
r=12
r=3
** The order of the output is not important. So, this output is also valid
r=12
r=3
r=9
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions