<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/'><id>tag:blogger.com,1999:blog-11200164.post181016459060919936..comments</id><updated>2011-03-09T01:20:34.909-05:00</updated><category term='Python'/><category term='Performance'/><category term='Architecture'/><category term='Evars'/><category term='Hibernate'/><category term='AJAX'/><category term='String'/><category term='Parsing'/><category term='Pragmatic'/><category term='Beer'/><category term='Future'/><category term='Concurrency'/><category term='Programming'/><category term='Felix'/><category term='event sourcing'/><category term='Web Development'/><category term='Opinion'/><category term='Scala'/><category term='Community'/><category term='Collections'/><category term='TDD'/><category term='Server Side'/><category term='hardware'/><category term='Software Development'/><category term='URL'/><category term='UML'/><category term='XML'/><category term='Modeling'/><category term='Design'/><category term='Java VM'/><category term='Java'/><category term='Data Driven'/><category term='Null'/><category term='Extreme Programming'/><category term='Refactoring'/><category term='Open Source'/><category term='OPath'/><category term='Competition'/><category term='Loud Thinking'/><category term='PyConsole'/><category term='Linux'/><category term='Eclipse'/><category term='How-to'/><category term='Debug'/><category term='Tooling'/><category term='Frustrations'/><category term='Non-tech'/><category term='Patterns'/><category term='blogging'/><category term='Ant'/><category term='Gargbage Collection'/><category term='Optimization'/><title type='text'>Comments on Nirav's Contemplations: Why Concurrency is hard</title><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://blog.nirav.name/feeds/181016459060919936/comments/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/11200164/181016459060919936/comments/default'/><link rel='alternate' type='text/html' href='http://blog.nirav.name/2011/03/why-concurrency-is-hard.html'/><author><name>Nirav Thaker</name><uri>http://www.blogger.com/profile/07204297663478577248</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://1.bp.blogspot.com/_PebfjbIpLKY/SYO5wL9XgUI/AAAAAAAAByY/MhgUWfUq5Hc/S220/DSCN1212+-+Copy.JPG'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>5</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-11200164.post-4787772805235910525</id><published>2011-03-09T01:20:34.909-05:00</published><updated>2011-03-09T01:20:34.909-05:00</updated><title type='text'>Hi Nirav,

I know the AtomicXXX implementations ve...</title><content type='html'>Hi Nirav,&lt;br /&gt;&lt;br /&gt;I know the AtomicXXX implementations very well.&lt;br /&gt;&lt;br /&gt;The operation you want to do, setting a value, doesn&amp;#39;t need more &amp;#39;atomicity&amp;#39; than an atomic set. The new value is a local variable and not subject to any currency issues.&lt;br /&gt;&lt;br /&gt;For the getAndSet it is a different matter since you want to have the value that existed prior to doing the write, so the get and set needs to be atomic, hence you need to do it in a loop and use a compareAndSwap.&lt;br /&gt;&lt;br /&gt;Peter Veentjer&lt;br /&gt;Multiverse:Software Transactional Memory for the JVM&lt;br /&gt;http://multiverse.codehaus.org</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/11200164/181016459060919936/comments/default/4787772805235910525'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/11200164/181016459060919936/comments/default/4787772805235910525'/><link rel='alternate' type='text/html' href='http://blog.nirav.name/2011/03/why-concurrency-is-hard.html?showComment=1299651634909#c4787772805235910525' title=''/><author><name>pveentjer</name><uri>http://www.blogger.com/profile/17847641595368096163</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://blog.nirav.name/2011/03/why-concurrency-is-hard.html' ref='tag:blogger.com,1999:blog-11200164.post-181016459060919936' source='http://www.blogger.com/feeds/11200164/posts/default/181016459060919936' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-1173593952'/></entry><entry><id>tag:blogger.com,1999:blog-11200164.post-2294292495625084583</id><published>2011-03-08T19:33:15.999-05:00</published><updated>2011-03-08T19:33:15.999-05:00</updated><title type='text'>Not sure why URLs was truncated. Here&amp;#39;s the li...</title><content type='html'>Not sure why URLs was truncated. Here&amp;#39;s the link &lt;br /&gt;&lt;a href="http://www.docjar.com/html/api/java/util/concurrent/atomic/AtomicReference.java.html" rel="nofollow"&gt;AtomicReference&lt;/a&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/11200164/181016459060919936/comments/default/2294292495625084583'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/11200164/181016459060919936/comments/default/2294292495625084583'/><link rel='alternate' type='text/html' href='http://blog.nirav.name/2011/03/why-concurrency-is-hard.html?showComment=1299630795999#c2294292495625084583' title=''/><author><name>Nirav Thaker</name><uri>http://www.blogger.com/profile/07204297663478577248</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://1.bp.blogspot.com/_PebfjbIpLKY/SYO5wL9XgUI/AAAAAAAAByY/MhgUWfUq5Hc/S220/DSCN1212+-+Copy.JPG'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://blog.nirav.name/2011/03/why-concurrency-is-hard.html' ref='tag:blogger.com,1999:blog-11200164.post-181016459060919936' source='http://www.blogger.com/feeds/11200164/posts/default/181016459060919936' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-1065815620'/></entry><entry><id>tag:blogger.com,1999:blog-11200164.post-2615307307667937208</id><published>2011-03-08T19:31:00.112-05:00</published><updated>2011-03-08T19:31:00.112-05:00</updated><title type='text'>I agree with your first suggestions but not with s...</title><content type='html'>I agree with your first suggestions but not with second one, the atomicity is only guaranteed if you use atomicRef.get() see correct implementation for getAndSet() http://www.docjar.com/html/api/java/util/concurrent/atomic/AtomicReference.java.html&lt;br /&gt;&lt;br /&gt;Thanks for pointing out the typo!</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/11200164/181016459060919936/comments/default/2615307307667937208'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/11200164/181016459060919936/comments/default/2615307307667937208'/><link rel='alternate' type='text/html' href='http://blog.nirav.name/2011/03/why-concurrency-is-hard.html?showComment=1299630660112#c2615307307667937208' title=''/><author><name>Nirav Thaker</name><uri>http://www.blogger.com/profile/07204297663478577248</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://1.bp.blogspot.com/_PebfjbIpLKY/SYO5wL9XgUI/AAAAAAAAByY/MhgUWfUq5Hc/S220/DSCN1212+-+Copy.JPG'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://blog.nirav.name/2011/03/why-concurrency-is-hard.html' ref='tag:blogger.com,1999:blog-11200164.post-181016459060919936' source='http://www.blogger.com/feeds/11200164/posts/default/181016459060919936' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-1065815620'/></entry><entry><id>tag:blogger.com,1999:blog-11200164.post-4356172922598564430</id><published>2011-03-08T10:35:14.065-05:00</published><updated>2011-03-08T10:35:14.065-05:00</updated><title type='text'>Ps:
the following code can be simplified:

while (...</title><content type='html'>Ps:&lt;br /&gt;the following code can be simplified:&lt;br /&gt;&lt;br /&gt;while (true) {&lt;br /&gt;    V x = atomicRef.get();&lt;br /&gt;   if (atomicRef.cas(x,newValue))&lt;br /&gt;     return atomicRef.get();&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;To&lt;br /&gt;&lt;br /&gt;atomicRef.set(newValue)&lt;br /&gt;return newValue&lt;br /&gt;&lt;br /&gt;No need to do that in a loop.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/11200164/181016459060919936/comments/default/4356172922598564430'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/11200164/181016459060919936/comments/default/4356172922598564430'/><link rel='alternate' type='text/html' href='http://blog.nirav.name/2011/03/why-concurrency-is-hard.html?showComment=1299598514065#c4356172922598564430' title=''/><author><name>pveentjer</name><uri>http://www.blogger.com/profile/17847641595368096163</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://blog.nirav.name/2011/03/why-concurrency-is-hard.html' ref='tag:blogger.com,1999:blog-11200164.post-181016459060919936' source='http://www.blogger.com/feeds/11200164/posts/default/181016459060919936' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-1173593952'/></entry><entry><id>tag:blogger.com,1999:blog-11200164.post-4483324848362123452</id><published>2011-03-08T10:28:20.455-05:00</published><updated>2011-03-08T10:28:20.455-05:00</updated><title type='text'>I think you have a JMM problem here depending on i...</title><content type='html'>I think you have a JMM problem here depending on if the aRef is or is not volatile&lt;br /&gt;&lt;br /&gt;synchronized(this){ aRef = newVal;} return aRef;&lt;br /&gt;&lt;br /&gt;It could be that the aRef is updated by another thread after the {...} logic is executed. This could lead to various jmm problems.&lt;br /&gt;&lt;br /&gt;It is better to use this:&lt;br /&gt;&lt;br /&gt;synchronized(this){ &lt;br /&gt;   aRef = newVal; &lt;br /&gt;   return aRef;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;But I agree that concurrency can be hard and having it all over the place in a normal system, doesn&amp;#39;t make me a happy man.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/11200164/181016459060919936/comments/default/4483324848362123452'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/11200164/181016459060919936/comments/default/4483324848362123452'/><link rel='alternate' type='text/html' href='http://blog.nirav.name/2011/03/why-concurrency-is-hard.html?showComment=1299598100455#c4483324848362123452' title=''/><author><name>pveentjer</name><uri>http://www.blogger.com/profile/17847641595368096163</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://blog.nirav.name/2011/03/why-concurrency-is-hard.html' ref='tag:blogger.com,1999:blog-11200164.post-181016459060919936' source='http://www.blogger.com/feeds/11200164/posts/default/181016459060919936' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-1173593952'/></entry></feed>
