Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

What if CAS not supported by Processor  RSS feed

 
Kartik Patel
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java 5 uses atomic object (Lock) to provide alternative to synchronization. Lock is nothing but the hardware level constructs of CAS. What is some processors do not support CAS and I have code with Lock object being used in it?

I think it will break. Any idea?
[ April 14, 2008: Message edited by: Kartik Patel ]
 
chatchai chailuecha
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In "Java concurrency in practice" by Brian goetz

15.2.3. CAS Support in the JVM
On platforms supporting CAS, the runtime inlines them into the appropriate machine instruction(s); in the worst case, if a CAS-like instruction is not available the JVM uses a spin lock.


The javadoc about compareAndSet operation states that:

The specifications of these methods enable implementations to employ efficient machine-level atomic instructions that are available on contemporary processors. However on some platforms, support may entail some form of internal locking. Thus the methods are not strictly guaranteed to be non-blocking


I guess the spin lock will be used instead

[ April 14, 2008: Message edited by: chatchai chailuecha ]

[ April 14, 2008: Message edited by: chatchai chailuecha ]
[ April 14, 2008: Message edited by: chatchai chailuecha ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!