Understanding of the concept of thread "synchronization" in multithreading

Understanding of the concept of "synchronization" in multithreading?

I have been in touch with threads for a long time, and I only know that multi-threaded concurrency is likely to cause thread safety issues, so thread synchronization is required, that is, through synchronize, Lock, volatile, the classes under the JUC concurrency package, ThrealLocal, AQS, atomic variables and blocking queues, etc., achieve synchronization, but look back and think about what "synchronization" is? Do threads need to be synchronized? Or does the shared resource accessed need to be synchronized?

After all, is this the case?

When multiple threads access a shared variable concurrently, one of the threads modifies the variable and gets the modified value, while other threads get the variable because the variable value is not synchronized after being modified. The value before modification, which causes multiple threads to access the same variable but get different values. Is this situation "unsynchronized" in thread safety?
And if it is said that when the variable is modified, other threads can obtain the modified value, that is to say, after one thread modifies the variable, other threads obtain the modified value. Is this the case we are talking about "thread" Synchronize"? And all thread synchronization mechanisms including synchronize, lock, etc. are these just to get this situation? That is, all threads get the modified value.

The newcomer looks to Daniel to express his attitude, so that I can know that I have not misunderstood

insert image description here

Guess you like

Origin blog.csdn.net/qq_43221829/article/details/109402795