1

GATE CSE 2008

MCQ (Single Correct Answer)

+2

-0.6

The P and V operations on counting semaphores, where s is a counting semaphore, are defined as follows:

```
P(s): s = s-1;
if s < 0 then wait;
V(s) : s = s-1;
ifs <= 0 then wakeup a process waiting on s;
```

Assume that P_{b}and V_{b}the wait and signal operations on binary semaphores are provided. Two binary semaphores X_{b}and Y_{b}are used to implement the semaphore operations P(s) and V(s) as follows:```
P(s): P
```_{b} (X_{b});
S = s - 1;
if(s < 0){
V_{b}(X_{b});
P_{b}(Y_{b});
}
Else V_{b} (X_{b});
V(s): P_{b} (X_{b});
S = s + 1;
if(s <= 0) V_{b}(Y_{b});
V_{b}(X_{b});

The initial values of X_{b}and Y_{b}are respectively2

GATE CSE 2007

MCQ (Single Correct Answer)

+2

-0.6

Two processes, P1 and P2, need to access a critical section of code. Consider the following synchronization construct used by the processes:
Here wants1 and wants2 are shared variables, which are initialized to false. Which one of the following statements is TRUE about the above construct?

```
/* P1 */
while(true){
want s1=true;
while(wants2 == true){
/* Critical Section */
wants1 = false;
}
/* Reminder Section */
}
```

```
/* P2 */
while(true){
want s2=true;
while(wants1 == true){
/* Critical Section */
Wants2 = false;
}
/* Reminder Section */
}
```

3

GATE CSE 2006

MCQ (Single Correct Answer)

+2

-0.6

The atomic fetch-and-set x, y instruction unconditionally sets the memory location x to 1 and fetches the old value of x n y without allowing any intervening access to the memory location x. consider the following implementation of P and V functions on a binary semaphore S.

```
void P (binary_semaphore *s) {
unsigned y;
unsigned *x = &(s->value);
do {
fetch-and-set x, y;
} while (y);
}
void V (binary_semaphore *s) {
S->value = 0;
}
```

Which one of the following is true? 4

GATE CSE 2006

MCQ (Single Correct Answer)

+2

-0.6

Barrier is a synchronization construct where a set of processes synchronizes globally i.e. each process in the set arrives at the barrier and waits for all others to arrive and then all processes leave the barrier. Let the number of processes in the set be three and S be a binary semaphore with the usual P and V functions. Consider the following C implementation of a barrier with line numbers shown on left.

Which one of the following rectifies the problem in the implementation?

```
void barrier (void) {
1: P(S);
2: process_arrived++;
3: V(S);
4: while (process_arrived !=3);
5: P(S);
6: process_left++;
7: if (process_left==3) {
8: process_arrived = 0;
9: process_left = 0;
10: }
11: V(S);
}
```

The variables process_arrived and process_left are shared among all processes and are initialized to zero. In a concurrent program all the three processes call the barrier function when they need to synchronize globally.Which one of the following rectifies the problem in the implementation?

Questions Asked from Synchronization and Concurrency (Marks 2)

Number in Brackets after Paper Indicates No. of Questions

GATE CSE Subjects

Discrete Mathematics

Programming Languages

Theory of Computation

Operating Systems

Computer Organization

Database Management System

Data Structures

Computer Networks

Algorithms

Compiler Design

Software Engineering

Web Technologies

General Aptitude