What is the thread synchronization?

Run each service process, contains several processes (Thread), the thread is the basic unit of scheduling, the process is the basic unit of resource owners.

Thread has its own private data, such as stack and registers, while sharing the same virtual memory and global variables and other resources with other threads when multiple threads simultaneously read and write to a shared resource with time, will lead to conflict, this time on the need to introduce thread synchronization mechanism so that each thread a line up of a shared resource to operate, rather than simultaneously.

1. thread synchronization implementation is actually the thread queue .

2. To prevent the threads synchronize access to shared resources caused by the conflict.

3. variables need to be synchronized, constant not required (constant stored in the method area).

Code 4. Multiple threads access to shared resources may be the same code, there may be a different code; regardless of whether the same code, as long as these threads with a variable code access shared resources , it is between these threads You need to be synchronized.

Guess you like

Origin blog.csdn.net/datuzijean/article/details/87874331