A complaint has nothing to do with the subject:
To sum up the importance of multithreading-waiting for the wake-up Mechanism
Let's use a difficult example to explain the logic of waiting to wake up the machine. When we were young, we had a game and couldn't remember the name. We were a group of friends, one of the lucky ones is drawn out, and the others are running around and escaping from the lucky one. Rule: When the lucky one wants to catch one of the other friends, if the response is fast, say "wood (fixed, cannot be moved)", lucky little pot friends can not catch him, but to catch other, only when other friends come to touch him (the one in the wood) can they be saved. When all the trees are finished, the luckier friends will become lucky, at the same time, it is completely saved.
Analysis points: the best friend is like a CPU and is switching. The friend of wood is like a thread, and "Wood" is like wait (), if you touch him, it's like running y (), and saving the whole department is like running yall (),
The relationships between threads are the same, and there is no attachment between them. They compete for CPU resources and have their own opinions. They also unconditionally obstruct other threads from accessing shared resources. However, there are also many practical problems that require not only the same access requests to share resources, but also the interaction between threads and push forward through mutual communication.
Note: 1. In the loop type selection, it is best to use the while loop, which must be judged first,
2. Wake up with policyall () when multiple threads exist ();
Simple wait wake-up mechanism code generation:
The article ends with sharing some jokes and quotations from programmers:
View of love
Love is an endless loop, and once executed, it gets stuck.
Falling in love with a person means memory leakage-you can never release it.
When you really fall in love with a person, it is constant limitation and will never change.
My girlfriend is a private variable. Only this class can be called.
The lover must pay attention when using the pointer. Otherwise, it will bring about a huge disaster.