Detailed analogy of lock and lock granularity

Source: Internet
Author: User
Today, I see an article that describes in detail the concept of lock and lock granularity, and why should I lock it as follows? Locking is designed to prevent the confusion of different threads from accessing the same shared resource.
A metaphor: People are different threads, toilets are shared resources
When you are in the bathroom, you must lock the door, this is the lock, as long as you are inside, the bathroom is locked, only after you come out to be used by others. Imagine what it would look like if the bathroom door was unlocked.
What is the size of the lock? The so-called lock granularity is how much you want to lock the range.
For example, you are in the bathroom at home, you just lock the bathroom can be, do not need to lock the whole house to let the family door, the bathroom is your lock granularity.
How to calculate the reasonable lock granularity?
In fact, the bathroom is not just for the toilet, but also can bathe, wash hands. This involves the optimization of the lock granularity problem.
You bathe in the bathroom, in fact, others can also go inside to wash their hands, as long as the isolation can be, if the toilet, bathtub, wash table are separated relatively independent, in fact, the bathroom can be used at the same time for three people,
Of course, three people do not do the same thing. This will refine the lock granularity, you can just close the bathroom door when you are in the shower, others may still go in to wash their hands. If the toilet was designed without dividing different functional areas
Can not achieve the maximum use of toilet resources. This is the importance of the design architecture. Thank you blog http://blog.chinaunix.net/uid-20758579-id-1876916.html

Detailed analogy of lock and lock granularity

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.