Understanding of threads and processes

Source: Internet
Author: User

Look at the image of the thread and the process of understanding, to stay as a souvenir.

This scene is like this, there is a temple in the mountains (the process ), the temple lived a lot of small monks and old monks ( threads ), of course, there are many nuns on the mountain next door sister. The Little Monk and the old monk need to carry water and drink down the mountain every day. These monks have just up the hill (is a bit silly), there are more intelligent, there are also noisy contradictions. The scene, the character, is probably the way it is.

As the saying goes, there are places where there are people. These little monks, old monks are not very good, in order to every day of this water work make a lot of contradictions, also made a lot of silly.

The following is a detailed description of all occurrences of water-carrying work:

1) Just up the hill of the Little monk water, is more silly that, and others do not know, every day to carry their own a person, pick a pail, one day down to find the water is not enough to drink. ( serial )

2 Monk inside there is a strong, and others bad relations, each time the water can pick three barrels or so, one day down, found to pick a barely enough to drink. ( concurrent )

3 Monk inside there are several relations good, the strength is also relatively big, each time carries water to go together, everybody can pick two barrels or so, one day down, found that the water is not only enough to drink, there is time to help the next-door Mountain nun sister carry water. ( parallel )

4) water in the well, there is a special sister in charge of water, the more silly the little monk every time staring at the girl, but also everywhere to see the bucket full of No ( synchronous ); Of course, there are silly, there are smart, this clever monk in the girl when the water, on the fly in the side of the rest, after the full , sister came to tell him. ( asynchronous )

5) There is no water in the well for a day, the silly monk saw no water in the well, the edge of the wells have been waiting, and so there is water to pick back ( blocking ); Clever monk, see the water in the well, do not hesitate to go back. ( non-blocking )

6) and one day, that made a contradiction of the two monks carrying water, just face to face, who will not let who past, has been deadlocked. ( deadlock )

7) The Temple kitchen space is limited, each time only to enter a certain number of monks, when the kitchen is full, others can only wait outside, until the people come out. The realization of the method is, the kitchen door hung a lot of locks, everyone went in after taking a lock, come out after the lock hanging, so that people outside can know the kitchen is full of people. ( signal Volume )

Mr. Yue
Links: https://www.zhihu.com/question/19901763/answer/121198143
Source: Know
Copyright belongs to the author, please contact the author for authorization.


1 Process Single-threaded: A person eats vegetables on a table.
2. Single process Multithreading: Many people eat food together on the same table.
3. Multi-process Single thread: Many people eat food on their own table.

Multi-threaded problem is that many people at the same time eat a dish when prone to scramble, for example, two person at the same time clip a dish, a person just out of chopsticks, the results reached the time has been clip away vegetables, at this time must wait for a person to clip a mouthful, in return to another person in the dish, that is, the sharing of resources
1: For Windows systems, the "open table" is expensive, so Windows encourages everyone to eat on a table. Therefore, the focus of Windows multithreaded learning is to face the problem of resource scrambling and synchronization.
2: For Linux systems, the "open table" is very inexpensive, so Linux encourages everyone to open their own table for food. This brings a new problem: sitting on two different desks, it's inconvenient to talk. Therefore, the learning focus of Linux is to learn the methods of inter-process communication.
Opening a table means creating a process. The overhead here mainly refers to the time overhead.
You can do an experiment: Create a process, write some data to memory in the process, read the data, and then exit. This process repeats 1000 times, which is equivalent to creating/destroying the process 1000 times. The test results on my machine are:
Ubuntulinux: 0.8 seconds
Windows7:79.8 seconds
The cost of the two is about 100 times times the difference. Pansz
Links: https://www.zhihu.com/question/19901763/answer/13299543
Source: Know
Copyright belongs to the author, please contact the author for authorization.

Understanding of threads and processes

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.