<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.0.2" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Use Total Ordering of Objects to Avoid Deadlocks</title>
	<link>http://jonasboner.com/2005/07/27/use-total-ordering-of-objects-to-avoid-deadlocks/</link>
	<description>Down To The Bone</description>
	<pubDate>Thu, 16 Oct 2008 06:57:51 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.2</generator>

	<item>
		<title>by: Tom Tromey</title>
		<link>http://jonasboner.com/2005/07/27/use-total-ordering-of-objects-to-avoid-deadlocks/#comment-3406</link>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid>http://jonasboner.com/2005/07/27/use-total-ordering-of-objects-to-avoid-deadlocks/#comment-3406</guid>
					<description>&lt;p&gt;Unfortunately, you can have two distinct objects
with identical identityHashCode()s.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Unfortunately, you can have two distinct objects
with identical identityHashCode()s.</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Marko Schulz</title>
		<link>http://jonasboner.com/2005/07/27/use-total-ordering-of-objects-to-avoid-deadlocks/#comment-3407</link>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid>http://jonasboner.com/2005/07/27/use-total-ordering-of-objects-to-avoid-deadlocks/#comment-3407</guid>
					<description>&lt;p&gt;I would make void Node#doSwap(Node) either private or name it something like doInsecureSwap(Node)&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I would make void Node#doSwap(Node) either private or name it something like doInsecureSwap(Node)</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Jonas</title>
		<link>http://jonasboner.com/2005/07/27/use-total-ordering-of-objects-to-avoid-deadlocks/#comment-3408</link>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid>http://jonasboner.com/2005/07/27/use-total-ordering-of-objects-to-avoid-deadlocks/#comment-3408</guid>
					<description>&lt;p&gt;Right, changed it to private...&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Right, changed it to private&#8230;</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Bob Lee</title>
		<link>http://jonasboner.com/2005/07/27/use-total-ordering-of-objects-to-avoid-deadlocks/#comment-3409</link>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid>http://jonasboner.com/2005/07/27/use-total-ordering-of-objects-to-avoid-deadlocks/#comment-3409</guid>
					<description>&lt;p&gt;Clever. To address Tom's point, you could keep an internal static counter instead of using the identity hash code. The exact details depend on the lifecycle of Node.&lt;/p&gt;

&lt;p&gt;I would probably decouple the client from the nodes using a container class.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Clever. To address Tom&#8217;s point, you could keep an internal static counter instead of using the identity hash code. The exact details depend on the lifecycle of Node.</p>

<p>I would probably decouple the client from the nodes using a container class.</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Newlukai</title>
		<link>http://jonasboner.com/2005/07/27/use-total-ordering-of-objects-to-avoid-deadlocks/#comment-3410</link>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid>http://jonasboner.com/2005/07/27/use-total-ordering-of-objects-to-avoid-deadlocks/#comment-3410</guid>
					<description>&lt;p&gt;I don't see, where there could be a deadlock. If you call n1.swap(n2), it invokes n1.get() and n2.swap(n1) invokes n2.get(). Both getters are locked.
When n1.get() returns n1.swap(n2) calls n2.get(), which is locked. But T2 doesn't need any n1 method at this time and finishes n2.get(), so n1.swap(n2) can invoke it. For T2, the n1.get() method is unlocked, so T2 calls n1.get().
So every thread is forced to wait sometime. Correct me if I'm wrong, but I don't see any deadlock.&lt;/p&gt;

&lt;p&gt;And your solution calls in both cases n1.doSwap(n2). In this case, it results the same way as n1.swap(n2) and n2.swap(n1) in the first listing do.
But this is, as I think, only because you swap data. If you calculate something or so, your solution could provide wrong results, because it invokes two times the same method on the same object.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I don&#8217;t see, where there could be a deadlock. If you call n1.swap(n2), it invokes n1.get() and n2.swap(n1) invokes n2.get(). Both getters are locked.
When n1.get() returns n1.swap(n2) calls n2.get(), which is locked. But T2 doesn&#8217;t need any n1 method at this time and finishes n2.get(), so n1.swap(n2) can invoke it. For T2, the n1.get() method is unlocked, so T2 calls n1.get().
So every thread is forced to wait sometime. Correct me if I&#8217;m wrong, but I don&#8217;t see any deadlock.</p>

<p>And your solution calls in both cases n1.doSwap(n2). In this case, it results the same way as n1.swap(n2) and n2.swap(n1) in the first listing do.
But this is, as I think, only because you swap data. If you calculate something or so, your solution could provide wrong results, because it invokes two times the same method on the same object.</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Jonas</title>
		<link>http://jonasboner.com/2005/07/27/use-total-ordering-of-objects-to-avoid-deadlocks/#comment-3411</link>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid>http://jonasboner.com/2005/07/27/use-total-ordering-of-objects-to-avoid-deadlocks/#comment-3411</guid>
					<description>&lt;p&gt;A synchronized member method is locking the instance (e.g. synchronized(this)), not the method itself.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>A synchronized member method is locking the instance (e.g. synchronized(this)), not the method itself.</p>
]]></content:encoded>
				</item>
</channel>
</rss>
