UI sister today praised me grow really handsome, “where where, literally” long “oh ~ ~, thanks for the compliment, I prefer your eyes” “like you the appearance of priggish said euphemism for” compliment, happy don’t put in his heart, and easy to accept and still can make fun, can foil a distinctive charm you

Guaranteed atomicity

Principle: Synchronized ensures that only one thread at a time acquires the lock and can access the synchronized code block.

Guaranteed visibility

Principle: When synchronized is executed, the corresponding lock atomic operation refreshes the value of the shared variable

Ensure order

Why reorder

To make the program more efficient, the compiler and CPU reorder the code in the program

The as – if – serial semantics

No matter how the compiler and CPU reorder, you must ensure that the program’s home country results are correct in the case of a single thread.

summary

With synchronized, reordering still occurs, except that we have synchronized code blocks that ensure that only one thread executes the code in synchronized code fast, thereby ensuring orderliness.

extension

Adding the volatile keyword before the num and ready shared variables also ensures order.