If we add a semaphore shared between P1 and P2 and change the pseudocode to the following one. What will be the final value of s? const int n=10; int s; // shared variable between two processes (threads) semaphore m=1; void P1( ) { int i=0; for (i=0;i

Systems Architecture
7th Edition
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Stephen D. Burd
Chapter11: Operating Systems
Section: Chapter Questions
Problem 14VE
icon
Related questions
Question
If we add a semaphore shared between P1 and P2 and change the pseudocode to the
following one. What will be the final value of s?
const int n=10;
int s;
// shared variable between two processes (threads)
semaphore m=1;
void P1( )
{
int i=0;
for (i=0;i<n, i++) {
semwait (m) ;
s+=i;
semSignal (m);
}
void P2()
{
int i=0;
for (i=0; i<n; i++) {
semWait (m):
s-=i;
semSignal (m);
}
}
void main ()
{
s=0;
Parbegin (Pl, P2);
//start two processes (threads)
Printout s;
Transcribed Image Text:If we add a semaphore shared between P1 and P2 and change the pseudocode to the following one. What will be the final value of s? const int n=10; int s; // shared variable between two processes (threads) semaphore m=1; void P1( ) { int i=0; for (i=0;i<n, i++) { semwait (m) ; s+=i; semSignal (m); } void P2() { int i=0; for (i=0; i<n; i++) { semWait (m): s-=i; semSignal (m); } } void main () { s=0; Parbegin (Pl, P2); //start two processes (threads) Printout s;
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning