Michael Heinen

Greenhorn
+ Follow
since Sep 08, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Michael Heinen

Hi all,
I don't understand the possible reuslts of the following question of Dan's study guide.

What are the possible results of attempting to compile and run the program?
a. Prints nothing.
b. Prints: [T1,A][T2,B].
c. Prints: [T1,B][T2,B].
d. Prints: [T2,B][T1,A].
e. Prints: [T2,A][T1,A].
f. Compiler error.
g. Run time error.
h. None of the above.
The right answers are b and d. I tried it out and this is right.
But I don't understand it.
There is only one instance of class B.
Class B has a member variable called s1, which is set in the synchronized method m1.
If this variable is set to "A" or to "B" and the yield method is called, I think it must be overwritten in the next call of m1 of the second thread.
So I expected, that the possbile results are c and e.
But this does not happen.
Can anybody explain this to me ?
Thanks in advance.
[ Jess added UBB [code] tags to preserve whitespace, check 'em out! ]
[ September 08, 2003: Message edited by: Jessica Sant ]