# Recent questions tagged process-synchronization

Two processes, P1 and P2, need to access a critical section of code. Consider the following synchronization construct used by the processes: /* P1 */ while (true) { wants1 = true; while (wants2 == true); /* Critical Section */ wants1 = false; } /* ... IT IS WRITTEN PROGRESS IS THERE? In the case when both wants1 and wants2 are true it will indefinitely be postponed then why progress is there?
Consider the following pseudocode, where $\textsf{S}$ is a semaphore initialized to $5$ in line $\#2$ and $\textsf{counter}$ is a shared variable initialized to $0$ in line $\#1$. Assume that the increment operation in line $\#7$ is $\textit{not}$ ... $0$ after all the threads successfully complete the execution of $\textsf{parop}$ There is a deadlock involving all the threads
1 vote
as per my knowledge of information in multicore systems we use spinlocks so that while one thread is busy waiting on while loop other thread can work on Critical section. my question is in gate question when busy waiting is being used using while loop do we always ... while one process is busy waiting no other process can work on CS. like in this qsn https://gateoverflow.in/1839/gate2006-61
How is the option C) satisfy bounded waiting? I mean, there can be a case where the process Q keeps on executing the while loop while process P doesn’t even get the chance. Bounded waiting is the number of times/bounds after which a process gets the chance to enter the critical section. The above code clearly does not support bounded wait, even with option C. Can anyone explain? Thanks!
this code does not provide ME Progress Bounded Waiting it is a correct synchronization problem given answer is (d) but how it is free from starvation
Can anyone tell from where to perfect topics – Synchronization and Concurrency in OS? Or how to become self efficient to solve questions in exam
Consider the following implementation of a general (counting) semaphore. This implementation assumes the existence of binary semaphore operations upb and downb implemented with a test-and-set instruction. Procedure UP( S : semaphore): downb(mutex) S := S + 1 if (S ... a preemptive or non-preemptive version) c) Priority (you may assign whatever priorities to the processes you wish) d) Round-Robin
Consider the following implementation of a general (counting) semaphore. This implementation assumes the existence of binary semaphore operations upb and downb implemented with a test-and-set instruction. Procedure UP( S : semaphore): downb(mutex) S := S + 1 if (S ... a preemptive or non-preemptive version) c) Priority (you may assign whatever priorities to the processes you wish) d) Round-Robin
In a virtual memory system, size of virtual address is 32-bit, size of physical address is 30-bit, page size is 4 Kbyte and size of each page table entry is 32-bit. The main memory is byte addressable. i. What is the size of main memory? ii. Find out, number of frames in main memory. iii. Find out, number of bits used for storing other information in frame.
SJF scheduling algorithm is frequently used in Long Term scheduling Short term scheduling both A and B None of these.
A multithreaded program $P$ executes with $x$ number of threads and uses $y$ number of locks for ensuring mutual exclusion while operating on shared memory locations. All locks in the program are non-reentrant, i.e., if a thread holds a lock $l$, then it cannot re-acquire lock $l$ without releasing it. If a thread is ... deadlock are: $x = 1, y = 2$ $x = 2, y = 1$ $x = 2, y = 2$ $x = 1, y = 1$
A certain computation generates two arrays a and b such that $a[i] = f(i)$ for $0 \leq i < n$ and $b[i] = g(a[i])$ for $0 \leq i < n$. Suppose this computation is decomposed into two concurrent processes $X$ and $Y$ such that $X$ computes the array $a$ and $Y$ computes the array $b$. The processes ... R); } EntryY(R, S) { V(S); P(R); } ExitX(R, S) { V(R); P(S); } EntryY(R, S) { V(S); P(R); }
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$ ... $L$ can take on a non-zero value when the lock is actually available works correctly but may starve some processes works correctly without starvation
The atomic fetch-and-set $x, y$ instruction unconditionally sets the memory location $x$ to $1$ and fetches the old value of $x$ in $y$ without allowing any intervening access to the memory location $x$. Consider the following implementation of $P$ and $V$ functions ... -set, a pair of normal load/store can be used The implementation of $V$ is wrong The code does not implement a binary semaphore
The enter_CS() and leave_CS() functions to implement critical section of a process are realized using test-and-set instruction as follows: void enter_CS(X) { while(test-and-set(X)); } void leave_CS(X) { X = 0; } In the above solution, $X$ is a memory location associated with the $CS$ ... $CS$ at the same time Which of the above statements are TRUE? (I) only (I) and (II) (II) and (III) (IV) only
Given below is a program which when executed spawns two concurrent processes : semaphore $X : = 0 ;$ /* Process now forks into concurrent processes $P1$ & $P2$ */ $\begin{array}{|l|l|}\hline \text{$P1$} & \text{$P2$} \\\hline \text{repeat forever } & \text{repeat forever} \\ \text{$V ... (I) and (II) are true. (I) is true but (II) is false. (II) is true but (I) is false Both (I) and (II) are false
The following program consists of $3$ concurrent processes and $3$ binary semaphores. The semaphores are initialized as $S0=1, S1=0$ and $S2=0.$ ... $P0$ print '$0$'? At least twice Exactly twice Exactly thrice Exactly once
Each Process $P_i$, i = $1....9$ is coded as follows repeat P(mutex) {Critical section} V(mutex) forever The code for $P_{10}$ is identical except it uses V(mutex) in place of P(mutex). What is the largest number of processes that can be inside the critical section at any moment? $1$ $2$ $3$ None
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 ... to $10$ need not be inside a critical section The barrier implementation is correct if there are only two processes instead of three.
Two processes $X$ and $Y$ ... deadlock The proposed solution guarantees mutual exclusion and prevents deadlock The proposed solution fails to prevent deadlock and fails to guarantee mutual exclusion
Two processes, $P1$ and $P2$, need to access a critical section of code. Consider the following synchronization construct used by the processes: /* P1 */ while (true) { wants1 = true; while (wants2 == true); /* Critical Section */ ... ensure bounded waiting. It requires that processes enter the critical section in strict alteration. It does not prevent deadlocks, but ensures mutual exclusion.
A shared variable $x$, initialized to zero, is operated on by four concurrent processes $W, X, Y, Z$ as follows. Each of the processes $W$ and $X$ reads $x$ from memory, increments by one, stores it to memory, and then terminates. Each of the processes $Y$ and $Z$ ... $S$ is initialized to two. What is the maximum possible value of $x$ after all processes complete execution? $-2$ $-1$ $1$ $2$
Consider the methods used by processes $P1$ and $P2$ for accessing their critical sections whenever needed, as given below. The initial values of shared boolean variables $S1$ and $S2$ ... properties achieved? Mutual exclusion but not progress Progress but not mutual exclusion Neither mutual exclusion nor progress Both mutual exclusion and progress
Consider Peterson's algorithm for mutual exclusion between two concurrent processes i and j. The program executed by process is shown below. repeat flag[i] = true; turn = j; while (P) do no-op; Enter critical section, perform actions, then exit critical section Flag[i] = false; Perform other non- ... turn = i flag[j] = true and turn = j flag[i] = true and turn = j flag[i] = true and turn = i
Consider the following two-process synchronization solution. ... two- process synchronization solution. This solution violates mutual exclusion requirement. This solution violates progress requirement. This solution violates bounded wait requirement.
Let $m[0]\ldots m[4]$ be mutexes (binary semaphores) and $P[0]\ldots P[4]$ be processes. Suppose each process $P[i]$ executes the following: wait (m[i]; wait (m(i+1) mod 4]); ........... release (m[i]); release (m(i+1) mod 4]); This could cause Thrashing Deadlock Starvation, but not deadlock None of the above
Consider three concurrent processes $P1$, $P2$ and $P3$ as shown below, which access a shared variable $D$ that has been initialized to $100$ ... the minimum and maximum possible values of $D$ after the three processes have completed execution are $X$ and $Y$ respectively, then the value of $Y-X$ is ____
A counting semaphore was initialized to $10$. Then $6 P$ (wait) operations and $4V$ (signal) operations were completed on this semaphore. The resulting value of the semaphore is $0$ $8$ $10$ $12$
Consider the procedure below for the Producer-Consumer problem which uses semaphores: semaphore n = 0; semaphore s = 1; void producer() { while(true) { produce(); semWait(s); addToBuffer(); semSignal(s); semSignal(n); } } void consumer() { while(true) { semWait(s) ... semaphore s when the buffer is empty. The starting value for the semaphore $n$ must be $1$ and not $0$ for deadlock-free operation.
Consider the following solution to the producer-consumer synchronization problem. The shared buffer size is $N$. Three semaphores $empty$, $full$ and $mutex$ are defined with respective initial values of $0, N$ and $1$. Semaphore $empty$ denotes the number of available slots in the buffer, for the consumer to read ... $P: empty, \ \ \ Q:full, \ \ \ R:full, \ \ \ S:empty$
Suppose we want to synchronize two concurrent processes $P$ and $Q$ using binary semaphores $S$ and $T$. The code for the processes $P$ and $Q$ ... $Z, S$ initially $1$ $V(S)$ at $W, V(T)$ at $X, P(S)$ at $Y, P(T)$ at $Z, S$ and $T$ initially $1$
Two concurrent processes $P1$ and $P2$ use four shared resources $R1, R2, R3$ and $R4$, as shown below. $\begin{array}{|l|l|}\hline \textbf{P1} & \textbf{P2} \\ \text{Compute: } & \text{Compute;} \\ \text{Use$R1;$} & \text{Use$R1; ... processes. If only binary semaphores are used to enforce the above scheduling constraints, what is the minimum number of binary semaphores needed? $1$ $2$ $3$ $4$
Consider the solution to the bounded buffer producer/consumer problem by using general semaphores $S, F,$ and $E$. The semaphore $S$ is the mutual exclusion semaphore initialized to $1$. The semaphore $F$ corresponds to the number of free slots in the buffer and is initialized to $N$. The ... $(F)$ in the Consumer process (I) only (II) only Neither (I) nor (II) Both (I) and (II)
Processes $P1$ and $P2$ use critical_flag in the following routine to achieve mutual exclusion. Assume that critical_flag is initialized to FALSE in the main program. get_exclusive_access ( ) { if (critical _flag == FALSE) { critical_flag = TRUE ; critical_region () ; critical_flag = FALSE; } } Consider ... ) is true Both (i) and (ii) are false (i) is true (ii) is false Both (i) and (ii) are true
Consider two processes $P_1$ and $P_2$ accessing the shared variables $X$ and $Y$ protected by two binary semaphores $S_X$ and $S_Y$ respectively, both initialized to 1. $P$ and $V$ denote the usual semaphore operators, where $P$ decrements the semaphore value, and $V$ increments the semaphore value. The pseudo- ... $P(S_X), P(S_X); P(S_Y), P(S_Y)$ $P(S_X), P(S_Y); P(S_X), P(S_Y)$
The following two functions $P1$ and $P2$ that share a variable $B$ with an initial value of $2$ ... $B$ can possibly take after the execution is______________________.
The following is a code with two threads, producer and consumer, that can run in parallel. Further, $S$ and $Q$ are binary semaphores quipped with the standard $P$ and $V$ operations. semaphore S = 1, Q = 0; integer x; producer: consumer: while (true) ... producer may be lost Values generated and stored in '$x$' by the producer will always be consumed before the producer can generate a new value
Consider the following snapshot of a system running $n$ concurrent processes. Process $i$ is holding $X_i$ instances of a resource $R$, $1 \leq i \leq n$. Assume that all instances of $R$ are currently in use. Further, for all $i$, process $i$ can place a request for at most $Y_i$ additional instances ... $\text{Min}(X_p,X_q) \leq \text{Max} \{Y_k \mid 1 \leq k \leq n, k \neq p, k \neq q\}$