a) What issue can arise if Thread 1 and Thread2 execute the following code concu
ID: 3816879 • Letter: A
Question
a) What issue can arise if Thread 1 and Thread2 execute the following code concurrently?
int count;
Thread1:
…
if (count > 0)
printf(“count value %d ”, count);
Thread2:
count = 0;
….
Answer:
b) What issue can arise if Thread 1 and Thread2 execute the following pseudo-code to lock two mutex locks (L1 and L2) concurrently? Explain.
Thread 1: Thread2:
Lock (L1); Lock(L2)
Lock(L2); Lock(L1)
Answer:
Explanation / Answer
a. If two threads simultaneously attempt to update a global counter variable, it is possible for their operations to interleave in such way that the global state is not correctly modified. such a case only arise only one time out.
b. Deadlock issue arises in this case. A deadlock is a situation where threads are blocked because one or both are waiting for access to a resource that will not be freed. The application can never terminate because the threads are blocked indefinitely. Here the threads are locked one after the other. So the dead lock situation arises.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.