How to practice concept:threads

Attempt a question, record the concept and assumptions, then check the available answer. Rework mistakes after revising the relevant concepts. Topic tags can overlap; review the question context.

Questions 1–10 of 10. Imported answers require independent review unless marked reviewed.

Topic practice 10 questionsPage 1 of 1

Question 24

Open question
CS1MSQ1 markNeeds review
Which of the following statements about threads is/are TRUE?
Your answerSelect all correct options. You can choose more than one.

Log in to check the answer

You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answer

Question 40

Open question
CS1MCQ2 marksNeeds review
Consider the following two threads T1 and T2 that update two shared variables a and b. Assume that initially a = b = 1. Though context switching between threads can happen at any time, each statement of T1 or T2 is executed atomically.
T1: a = a + 1; b = b + 1;
T2: b = 2 * b; a = 2 * a;
Which one of the following options lists all the possible combinations of values of a and b after both T1 and T2 finish execution?
Your answerChoose one option.

Log in to check the answer

You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answer

Question 46

Open question
CSMSQ2 marksNeeds review
Consider a multi-threaded program with two threads T1 and T2. The threads share two semaphores: s1 (initialized to 1) and s2 (initialized to 0). The threads also share a global variable x (initialized to 0). The threads execute the code shown below.
// code of T1 // code of T2
wait(s1); wait(s1);
x = x+1; x = x+1;
print(x); print(x);
wait(s2); signal(s2);
signal(s1); signal(s1);
Which of the following outcomes is/are possible when threads T1 and T2 execute concurrently?
Your answerSelect all correct options. You can choose more than one.

Log in to check the answer

You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answer

Question 38

Open question
CSMCQ2 marksNeeds review
Consider the two functions inc and dec shown below.
inc(){ dec(){
wait(s); wait(s);
X = X+1; X = X-1;
signal(s); signal(s);
} }
There are 5 threads each invoking inc once, and 3 threads each invoking dec once, on the same shared variable X. The initial value of X is 10.
Suppose there are two implementations of the semaphore s, as follows:
I-1: s is a binary semaphore initialized to 1.
I-2: s is a counting semaphore initialized to 2.
Let V1, V2 be the values of X at the end of execution of all the threads with implementations I-1, I-2, respectively.
Which one of the following choices corresponds to the minimum possible values of V1, V2, respectively?
Your answerChoose one option.

Log in to check the answer

You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answer

Question 19

Open question
CSMCQ1 markNeeds review
Consider the following threads, T₁, T₂, and T₃ executing on a single processor, synchronized using three binary semaphore variables, S₁, S₂, and S₃, operated upon using standard wait() and signal(). The threads can be context switched in any order and at any time.
Diagram for Computer Science and Information Technology question 19

Which initialization of the semaphores would print the sequence BCABCABCA....?
Your answerChoose one option.

Log in to check the answer

You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answer

Question 42

Open question
CSMSQ2 marksNeeds review
Consider the following multi-threaded code segment (in a mix of C and pseudo-code), invoked by two processes P1 and P2, and each of the processes spawns two threads T1 and T2:
int x = 0; // global
Lock L1; // global
main() {
create a thread to execute foo(); // Thread T1
create a thread to execute foo(); // Thread T2
wait for the two threads to finish execution;
print (x);
}

foo() {
int y = 0;
Acquire L1;
x = x + 1;
y = y + 1;
Release L1;
print (y);
}
Which of the following statement(s) is/are correct?
Your answerSelect all correct options. You can choose more than one.

Log in to check the answer

You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answer

Question 46

Open question
CSMSQ2 marksNeeds review
Consider the following pseudocode, where S is a semaphore initialized to 5 in line#2 and counter is a shared variable initialized to 0 in line#1. Assume that the increment operation in line#7 is not atomic.
int counter = 0;
Semaphore S = init(5);
void parop(void)
{

wait(S);

wait(S);

counter++;

signal(S);

signal(S);
} If five threads execute the function parop concurrently, which of the following program behavior(s) is/are possible?
Your answerSelect all correct options. You can choose more than one.

Log in to check the answer

You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answer

Question 7

Open question
CSMCQ1 markNeeds review
Which of the following is/are shared by all the threads in a process?
I. Program counter II. Stack III. Address space IV. Registers
Your answerChoose one option.

Log in to check the answer

You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answer

Question 18

Open question
CSMCQ1 markNeeds review
Threads of a process share
Your answerChoose one option.

Log in to check the answer

You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answer

Question 27

Open question
CSMCQ2 marksNeeds review
A multithreaded program P 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 blocks until the lock becomes available. The minimum value of

and the minimum value of

together for which execution of P can result in a deadlock are:
Your answerChoose one option.

Log in to check the answer

You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answer