Multithreading-three major laws of concurrency

Source: Internet
Author: User
Tags cas

Three major laws of concurrency


Amdahl Law
–gene Amdahl found that in the design process of computer architecture, the optimization of one component has an upper limit on the optimization and improvement of the whole architecture. The discovery later became a well-known Amdahl law.
For example: Even if you have 10 wives, you can not give birth to a child for one months.


Gustafson Law
–gustafson assumes that as the number of processors increases, the amount of parallel and serial computation can also be increased. Gustafson Law thinks that the acceleration coefficient is almost proportional to the number of processors, and if the reality conforms to the assumptions of the Gustafson law, then the performance of the software can increase with the number of processing.
For example: When you have 10 wives, you will have more children.


Sun-ni Law
– Leverage computing resources such as storage space to maximize problem size to produce better/more accurate solutions.
For example: You have to try to make every wife work, don't let them idle.


---------------------------------------------Gorgeous split-line-------------------------------------


1. What is the future for?


Reference: http://blog.csdn.net/simonchi/article/details/8181571


2. What is the difference between lock and synchronized?


Synchronized is a simplified implementation of lock, where a lock can correspond to multiple condition, and synchronized combines lock and condition, A synchronizedlock only corresponds to one condition, which can be said that synchronized is a simplified version of lock.
Jdk5,synchronized is much slower than lock, but in JDK6, they are almost as efficient.


Reference: http://blog.csdn.net/tangkai177/article/details/7451797


3. Concurrent programming What is a CAS? (CAS full name is Compare and Swap)


You can use CAs to do atomic operations without locking, but to be clear about applications, it is very simple to use CAS operations and you do not want to introduce locks, and you can consider CAS when you want to do a non-blocking operation. The introduction of CAs in complex operations is not recommended, which makes the program less readable and difficult to test, and ABA problems occur.


Reference: http://my.oschina.net/lifany/blog/133513
Reference: http://blog.csdn.net/aesop_wubo/article/details/7537960




4. What are the three components of the lock-free algorithm?


They are usually made up of three parts:
① Cycle
②cas (Compareandset)
③ fallback


---------------------------------------------Gorgeous split-line-------------------------------------


After JDK 1.5 is scheduledexecutorservice, it is not recommended to use Java.util.Timer because it is not as functional as Scheduledexecutorservice


Pessimistic lock: It is assumed that concurrency conflicts occur and that all operations that may violate data integrity are masked.
Optimistic Lock: Assume that there will be no concurrency conflicts and only check for violation of data integrity when committing the operation. [1] Optimistic locking does not solve the problem of dirty reading.
Reference: http://www.cnblogs.com/guyufei/archive/2011/01/10/1931632.html


Related documents:
Http://en.wikipedia.org/wiki/Monitor_ (synchronization)

Multithreading-three major laws of concurrency

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.