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. What is one reason why thread two may not receive 7 and 8 on its two final calls to getSharedData?
Public class SharedData
{
Private int value;
Public void setSharedData(int n)
{
Value = n;
}
Public int getSharedData()
{
Return value;
}
}
A) Thread one produced two 8's.
B) Thread two is getting longer time slices.
C) Thread one is getting longer time slices.
D) The race condition.
Correct Answer:
Verified
Q41: Assume two threads share a BankAccount object
Q42: Assume two threads share a BankAccount object
Q47: Assume two threads share a BankAccount object
Q50: Consider the following change to the deposit
Q50: A waiting thread is blocked until another
Q51: _ allow a thread to temporarily release
Q54: Consider the addFirst method of the LinkedList
Q55: The _ method is called by a
Q58: If a thread sleeps after acquiring a
Q63: Calling the wait method in synchronized code
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents