Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  The following two functions P1 and P2 that sh... Start Learning for Free
The following two functions P1 and P2 that share a variable B with an initial value of 2 execute concurrently.
The number of distinct values that B can possibly take after the execution is __________.
    Correct answer is '3'. Can you explain this answer?
    Most Upvoted Answer
    The following two functions P1 and P2 that share a variable B with an ...
    Initial value of B is 2 //value stored in main memory
    Value of B = 4
    First execute P2()
    P2 ( ) {
    D = 2 * B;   // 2 × 2 = 4
    B = D – 1; // B = 4 – 1 = 3
    }
    write the value of B = 3 to memory
    execute P1()
    P1 ( ) {
    C = B – 1; // C = 3 – 1 = 2
    B = 2 * C; // B = 2 × 2 = 4
    }
    write the value of B = 4 is memory.
    Distinct value of B is 4.
    Value of B =3
    First Execute P1()
    P1 ( ) {
    C = B – 1; // C = 2 – 1 = 1
    B = 2 * C; // B = 2 × 1 =2
    }
    write the value of B = 2 to memory
    then execute P2()
    P2 ( ) {
    D = 2 * B;   // 2 × 2 = 4
    B = D – 1; // B = 4 – 1 = 3
    }
    write the value of B = 3 to memory
    One of the distinct values of B is 3.
    Value of B = 2
    First execute P2()
    P2 ( ) {
    D = 2 * B;   // 2 × 2 = 4
    B = D – 1; // B = 4 – 1 = 3
    }
    //don’t write to memory
    execute P1()  // with initial value of B = 2
    P1 ( ) {
    C = B – 1; // C = 2 – 1 = 1
    B = 2 * C; // B = 2 × 1 = 2
    }
    write the value B = 3 by P2() in memory.
    overwrite the value written by P2() as B = 2 by P1() in memory.
    One of the distinct values of B is 2.
    Therefore, the distinct values of B are 2, 3 and 4.
    The number of distinct values that B can possibly take after the execution is 3.
    Free Test
    Community Answer
    The following two functions P1 and P2 that share a variable B with an ...
    Initial value of B is 2 //value stored in main memory
    Value of B = 4
    First execute P2()
    P2 ( ) {
    D = 2 * B;   // 2 × 2 = 4
    B = D – 1; // B = 4 – 1 = 3
    }
    write the value of B = 3 to memory
    execute P1()
    P1 ( ) {
    C = B – 1; // C = 3 – 1 = 2
    B = 2 * C; // B = 2 × 2 = 4
    }
    write the value of B = 4 is memory.
    Distinct value of B is 4.
    Value of B =3
    First Execute P1()
    P1 ( ) {
    C = B – 1; // C = 2 – 1 = 1
    B = 2 * C; // B = 2 × 1 =2
    }
    write the value of B = 2 to memory
    then execute P2()
    P2 ( ) {
    D = 2 * B;   // 2 × 2 = 4
    B = D – 1; // B = 4 – 1 = 3
    }
    write the value of B = 3 to memory
    One of the distinct values of B is 3.
    Value of B = 2
    First execute P2()
    P2 ( ) {
    D = 2 * B;   // 2 × 2 = 4
    B = D – 1; // B = 4 – 1 = 3
    }
    //don’t write to memory
    execute P1()  // with initial value of B = 2
    P1 ( ) {
    C = B – 1; // C = 2 – 1 = 1
    B = 2 * C; // B = 2 × 1 = 2
    }
    write the value B = 3 by P2() in memory.
    overwrite the value written by P2() as B = 2 by P1() in memory.
    One of the distinct values of B is 2.
    Therefore, the distinct values of B are 2, 3 and 4.
    The number of distinct values that B can possibly take after the execution is 3.
    Explore Courses for Computer Science Engineering (CSE) exam

    Top Courses for Computer Science Engineering (CSE)

    The following two functions P1 and P2 that share a variable B with an initial value of 2 execute concurrently.The number of distinct values that B can possibly take after the execution is __________.Correct answer is '3'. Can you explain this answer?
    Question Description
    The following two functions P1 and P2 that share a variable B with an initial value of 2 execute concurrently.The number of distinct values that B can possibly take after the execution is __________.Correct answer is '3'. Can you explain this answer? for Computer Science Engineering (CSE) 2024 is part of Computer Science Engineering (CSE) preparation. The Question and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus. Information about The following two functions P1 and P2 that share a variable B with an initial value of 2 execute concurrently.The number of distinct values that B can possibly take after the execution is __________.Correct answer is '3'. Can you explain this answer? covers all topics & solutions for Computer Science Engineering (CSE) 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for The following two functions P1 and P2 that share a variable B with an initial value of 2 execute concurrently.The number of distinct values that B can possibly take after the execution is __________.Correct answer is '3'. Can you explain this answer?.
    Solutions for The following two functions P1 and P2 that share a variable B with an initial value of 2 execute concurrently.The number of distinct values that B can possibly take after the execution is __________.Correct answer is '3'. Can you explain this answer? in English & in Hindi are available as part of our courses for Computer Science Engineering (CSE). Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.
    Here you can find the meaning of The following two functions P1 and P2 that share a variable B with an initial value of 2 execute concurrently.The number of distinct values that B can possibly take after the execution is __________.Correct answer is '3'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of The following two functions P1 and P2 that share a variable B with an initial value of 2 execute concurrently.The number of distinct values that B can possibly take after the execution is __________.Correct answer is '3'. Can you explain this answer?, a detailed solution for The following two functions P1 and P2 that share a variable B with an initial value of 2 execute concurrently.The number of distinct values that B can possibly take after the execution is __________.Correct answer is '3'. Can you explain this answer? has been provided alongside types of The following two functions P1 and P2 that share a variable B with an initial value of 2 execute concurrently.The number of distinct values that B can possibly take after the execution is __________.Correct answer is '3'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice The following two functions P1 and P2 that share a variable B with an initial value of 2 execute concurrently.The number of distinct values that B can possibly take after the execution is __________.Correct answer is '3'. Can you explain this answer? tests, examples and also practice Computer Science Engineering (CSE) tests.
    Explore Courses for Computer Science Engineering (CSE) exam

    Top Courses for Computer Science Engineering (CSE)

    Explore Courses
    Signup for Free!
    Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
    10M+ students study on EduRev