1
You visited us
1
times! Enjoying our articles?
Unlock Full Access!
Byju's Answer
Other
Other
Test and Set Lock
Consider the ...
Question
Consider the following code of processes 'i' & 'j'
int lock = 0, turn;
void process (int i)
{
int j = NOT(i);
while (1)
{
turn = i;
while (lock ! = 0 && turn = = i);
lock = 1;
<CS>
lock = 0;
}
Which of the following is true?
Open in App
Solution
It fails to guarantee mutual exclusion
Suggest Corrections
0
Similar questions
Q.
TSL is used to synchronize processes as follows.
Following is the logic of process 'i' where varies from1 to n. All processes share a lock varible initialized to 0.
Process i
–
––––––––––––––––
–
While (1) {
int key;
DO: key =TSL(lock);
if (key == 1) goto DO;
C.S.
Lock =0 ;
}
–
––––––––––––––––
–
Which of the following statement is true?
Q.
Consider the following two-process synchronization soultion
Process 0
Entry: loop while (turn ==1);
(critical section)
Exit: turn =1;
Process 1
Entry: loop while (turn ==0);
(critical section)
Exit: turn =0;
The shared variable turn in initialized to zero.
Which one of the following is
TRUE
?
Q.
Fetch_And_Add(X,i) is an atomic Read-Modify-Write instruction that reads the value of memory location X, increments it by the value i, and returns the old value of X, it is used in the pseudocode shown below to implement a busy-wait lock. L is unsigned integer shared variable initialized to 0. The value of 0 corresponds to lock being available, while any non-zero value corresponds to the lock being not available.
AcquireLock (L) {
while (Fetch_And_Add(L,1))
L = 1;
}
Release Lock (L){
L=0;
}
This implementation
Q.
Consider the following C-function in which a [n] and b [m] are two sorted integer arrays and c [n+m] be another integer array.
void xyz (int a[ ], int b[ ], int c[ ])
{
int i, j, k;
i = j = k = 0;
while ((i < n) && (j < m))
if (a[i] < b[j])
c[k++] = a[i ++];
else
c[k++] = b[j ++];
}
Which of the following condition(s) hold after the termination of the while loop?
(i) j < m, k = n + j - 1 & a[n- 1] < b[j] if i = n
(ii) i < n, k = m + i - 1 & b[m- 1]
≤
a[i] if j = m
Q.
What does the following program print?
#include < stdio.h>
void f(int *p, int *q)
{
p = q;
*p = 2;
}
int i = 0, j = 1;
int main( )
{
f(&i, &j);
printf ("%d %d\n", i, j);
return 0;
}
View More
Join BYJU'S Learning Program
Grade/Exam
1st Grade
2nd Grade
3rd Grade
4th Grade
5th Grade
6th grade
7th grade
8th Grade
9th Grade
10th Grade
11th Grade
12th Grade
Submit
Related Videos
Test and Set Lock
OTHER
Watch in App
Explore more
Test and Set Lock
Other Other
Join BYJU'S Learning Program
Grade/Exam
1st Grade
2nd Grade
3rd Grade
4th Grade
5th Grade
6th grade
7th grade
8th Grade
9th Grade
10th Grade
11th Grade
12th Grade
Submit
Solve
Textbooks
Question Papers
Install app