Multiple Choice
Examine the SharedData class shown below. Suppose two threads are created so that each has access to the same SharedData object. Thread one calls setSharedData eight times with values 1...8 respectively, sleeping for 30 milliseconds between calls. Thread two calls getSharedData eight times, also sleeping for 30 milliseconds between calls. Suppose thread two receives values 1, 2, 3, 4, 5, 6, 7, 8 respectively on its calls. Should we expect the same values for each program run?
Public class SharedData
{
Private int value;
Public void setSharedData(int n)
{
Value = n;
}
Public int getSharedData()
{
Return value;
}
}
A) Yes, because the sleep times are equal in between calls.
B) Yes, because that's the same order used by thread one to set the values.
C) No, because thread one may not set the data as 1,2,3,4,5,6,7,8 respectively.
D) No, because a race condition may result in a different order.
Correct Answer:

Verified
Correct Answer:
Verified
Q15: Which of the following definitely indicates that
Q22: If a thread sleeps after acquiring a
Q26: Which of the following scenarios may not
Q44: When a thread is interrupted, the most
Q45: Stale data occurs in multi-CPU machines when
Q50: Which argument(s) present(s) the best case(s) for
Q52: Which method(s) are part of the Thread
Q73: Which of the following statements is correct?<br>A)If
Q75: Suppose thread one is downloading a 800KB
Q80: Suppose thread one is downloading a 800KB