GATE CS Concurrency and Synchronization questions
Practise Concurrency and Synchronization questions for GATE CS. Explore official PYQs and original topic-wise quizzes, check answers and view available solutions. Free, no sign-in.
Subject, topic, year and type filter the full library. Match any choice within a filter, and all selected filter categories. Search, source and sort apply to this page.
20 on this page
Consider three processes , and running identical code, as shown in the pseudocode below. and are two binary semaphores initialized to and , respectively. is a shared variable initialized to . Each line in the pseudocode is executed atomically. Pseudocode of P1, P2, and P3 …
Consider a multi-threaded program with two threads and . The threads share two semaphores: (initialized to ) and (initialized to ). The threads also share a global variable (initialized to ). The threads execute the code shown below. //code of T 1 wait (s1); x = x+1; print (x); …
Consider the two functions and shown below. incr(){ decr(){ wait(s); wait(s); X = X+1; X = X-1; signal(s); signal(s); } } There are threads each invoking once, and threads each invoking once, on the same shared variable . The initial value of is …
Consider the following threads, and executing on a single processor, synchronized using three binary semaphore variables, and operated upon using standard and The threads can be context switched in any order and at any …
Consider the following pseudocode, where is a semaphore initialized to in line and is a shared variable initialized to in line . Assume that the increment operation in line is atomic. 1. int counter = 0; 2. Semaphore S = init(5); 3. void parop(void) 4. { 5. wait(S); 6. …
Each of a set of processes executes the following code using two semaphores and initialized to and , respectively. Assume that is a shared variable initialized to and not used in CODE SECTION P. wait(a); count=count+1; if (count==n) …
Consider three concurrent processes and as shown below, which access a shared variable that has been initialized to …
Consider the following solution to the producer-consumer synchronization problem. The shared buffer size is . Three semaphores , and are defined with respective initial values of and . Semaphore denotes the number of available slots in the buffer, for the consumer to read from. Semaphore …
A multithreaded program executes with number of threads and uses 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 , then it cannot re-acquire lock without releasing it. If a thread is unable to acquire a lock, it …
Consider the following proposed solution for the critical section problem. There are processes : . In the code, function returns an integer not smaller than any of its arguments .For all is initialized to zero. Code for ; do { c[i]=1; t[i]= pmax (t[0],....,t[n-1])+1; c[i]=0; for every j != i in …
Consider the following two-process synchronization solution. …
Consider a non-negative counting semaphore . The operation decrements , and increments . During an execution, operations and operations are issued in some order. The largest initial value of for which at least one operation will remain blocked is _______
The following two functions and that share a variable with an initial value of execute concurrently. The number of …
Two processes and need to access a critical section. Consider the following synchronization construct used by both the processes …
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); semWait(n); removeFromBuffer(); semSignal(s); consume(); } } Which one of the following is …
A certain computation generates two arrays a and b such that for and for . Suppose this computation is decomposed into two concurrent processes and such that computes the array and computes the array . The processes employ two binary semaphores …
A shared variable , initialized to zero, is operated on by four concurrent processes as follows. Each of the processes and reads from memory, increments by one, stores it to memory, and then terminates. Each of the processes and reads from memory, decrements by two, stores it to memory, and then …
Fetch_And_Add(X,i) is an atomic Read-Modify-Write instruction that reads the value of memory location , increments it by the value , and returns the old value of . It is used in the pseudocode shown below to implement a busy-wait lock. is an unsigned integer shared variable initialized to . The value of corresponds to lock …
The following program consists of concurrent processes and binary semaphores. The semaphores are initialized as and …
Consider the methods used by processes and for accessing their critical sections whenever needed, as given below. The initial values of shared boolean variables and are randomly assigned. …
