This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
try to get a deadlock accessing via 2 threads 2 resources in synchronized blocks like:
synchronized(A){ synchronized(B){ } } and synchronized(B){ synchronized(A){ } } i try to put the threads on sleep, use system.outs just to make sure my threads are accessing these objects in a convenient way, i know this because i got this output(copied/pasted from one run): 1. u tryin to acquire lock on A 2. u got lock on A, tryin to get lock on B 3. v tryin to acquire lock on B 4. v got lock on B, tryin to get lock on A 5. v got lock on A 6. v thread, freed all locks 7. u got lock on B ... and so on..
so, my question, how's it possible to read the 5th line if the u thread has already the lock on A?
C:\Test>java TestThreadSync Thread T1 launched Thread T1 got lock on A Thread T2 launched Thread T2 got lock on B
And the program just hangs there. This is what I expected it to do when entered in a deadlock situation.
Vali GB
Greenhorn
Joined: Jun 06, 2004
Posts: 7
posted
0
Thanx a lot Siyaa!! your example worked just fine into a deadlock..of course
actually my test program ressembled a lot yours with a few differences, and I still can't understand something...
For example, if I modify your program just a bit :
the're will be no more deadlock:
Thread T1 launched Thread T1 got lock on A Thread T2 launched Thread T2 got lock on B T1 managed both T2 managed both Process terminated with exit code 0
Why?
Vali GB
Greenhorn
Joined: Jun 06, 2004
Posts: 7
posted
0
I somehow managed to solve the prev problem. It was about the share on the 2 objects I wanted to deadlock...