java - Atomic actions - what is meant by reads and writes? -


its 1 thing don't concurrency - threads , atomic-actions. according docs.oracle these actions specified atomic:

  • reads , writes atomic reference variables , primitive variables (all types except long , double).
  • reads , writes atomic variables declared volatile (including long , double variables).

but @ same time docs.oracle asserts incrementing variable not atomic action. thought write:

 private int number;  number++; 

obviously not understand meant "reads" , "writes".

could explain , give example of "reads" , "writes"?

edit: when doing without synchronization programs suffers ´thread interference. understand not atomic. when change variable belongs object these threads share - there no interference whatsoever. shared variable object changed via mutator.

in order implement number++, runtime needs to

  1. acquire current value of number (a read).

  2. increment value.

  3. write new value number (a write).

if thread starts 1 when you're @ 2 final value number incorrect since thread still reading original value.

if 1, 2 , 3 executed atomic operation (i.e. thread cannot start 1 until you've finished 3) well.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -