http://wangyuanzju.blog.163.com/blog/static/130292008031101953399/
http://en.wikipedia.org/wiki/Compare-and-swap
java 中应用到的CAS:
http://my.oschina.net/u/177808/blog/166819
http://hi.baidu.com/heelenyc/item/b7caf283b8610fceb17154e7
http://blog.csdn.net/hsuxu/article/details/9467651
Lock and Synchronized from Java doc:
Lock implementations provide more extensive locking operations than can be obtained using synchronized methods and statements. They allowmore flexible structuring, may have quite different properties, and maysupport multiple associated Condition objects.
...
The use of synchronized methods or statements provides access to the implicit monitor lock associated with every object, butforces all lock acquisition and release to occur in a block-structured way: whenmultiple locks are acquired theymust be released in the opposite order, and all locks must be released in the same lexical scope in which they were acquired.
While the scoping mechanism for synchronized methods and statementsmakes it much easier to program with monitor locks, and helpsavoid many common programming errors involving locks, there are occasions where you need to work with locks in a more flexible way. For example, **some algorithms* for traversing concurrently accessed data structuresrequire the use of "hand-over-hand" or "chain locking": you acquire the lock of node A, then node B, then release A and acquire C, then release B and acquire D and so on. Implementations of theLock interface enable the use of such techniques by allowing a lock to be acquired and released in different scopes, andallowing multiple locks to be acquired and released in any order.
With this increased flexibility comes additional responsibility. Theabsence of block-structured locking removes the automatic release of locks that occurs with synchronized methods and statements. In most cases, the following idiom should be used:
...
When locking and unlocking occur in different scopes, care must be taken toensure that all code that is executed while the lock is heldis protected by try-finally or try-catch to ensure that the lock is released when necessary.
Lock implementations provide additional functionality over the use of synchronized methods and statements by providing anon-blocking attempt to acquire a lock (tryLock()), an attempt toacquire the lock that can be interrupted (lockInterruptibly(), and an attempt toacquire the lock that can timeout (tryLock(long, TimeUnit)).
区别并不是CAS,两者底层是CAS:
区别:前者乐观锁,后者是悲观锁实现
http://developer.51cto.com/art/201111/304378.htm
http://developer.51cto.com/art/201111/304387.htm
http://my.oschina.net/u/557580/blog/225554
http://chenzehe.iteye.com/blog/1762893
https://docs.oracle.com/javase/tutorial/essential/concurrency/locksync.html
http://www.journaldev.com/2377/java-lock-example-and-concurrency-lock-vs-synchronized