statement re-order — within-thread^between-thread

— Based on

JVM can re-order statements. “Ordering rules fall under two cases, within-thread and between-thread: “

)) “From the point of view of the thread performing the actions in a method, instructions proceed in the normal as-if-serial manner that applies in sequential programming languages. “

%% As an observer of this thread, you can ignore the re-ordering and assume that “statements appearing earlier never runs later”. Behind-the-scene shuffle will never break a single-thread spectator’s expectation.%%

)) “From the point of view of other threads that might be “spying” on this thread by concurrently running unsynchronized methods, almost anything can happen. The only useful constraint is that the relative orderings of synchronized code, as well as operations on volatile fields, are always preserved. “

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s