CAS has two features:
1. For loop
2, Compareandset (possibly other threads change and then reset, at this time the CAS is successful, that is, the process of CAs execution, it is possible for multiple threads to modify this variable, rather than the individual thread mutually exclusive modification )
3, CAs and mutexes are different, CAs can be successfully executed by multiple threads at the same time.
Thread.Join ()
Here is the source code. A.jonin (b), so when B ends, it notifya, How does it happen ? Implementation is within the JVM, need to look at the JVM source code
Thread.Join ()
while (T.isalive ()) {
Wait (0);
}
Viii. concurrency tool Classes in Java (provides overloaded methods such as timeouts, including interfaces for querying thread queuing and statistics)
1, Countdownlatch
1. Cannot be reused
2, equivalent to Thread.Join ()
3. Call the Countdown method Happens-before, and another thread calls the await method.
2, Cyclicbarrier
1, can be used for multiple threads to calculate data, and finally consolidate the results of the scene.
2. The thread that merges the results of the calculation is the one that was last await.
3, you can reset the counter in the process of await
4, can query whether there is an await thread broken
3, Semaphore
1. The number of threads used to control access to a resource
4. Exchange
1, for the data exchange between threads.
2. There is a synchronization point between the two threads for data exchange on the synchronization point.
The art of Java concurrent programming