I have thread A and Thread B , what would happen if A reads an int value in A(itself) to check a condtion , while B is writing to the same value at the same time would an error occur ? or just desynchronization ?
2 Answers
What you've described is called a race condition. Each run of your program will have a different value stored in Thread A's memory where the result of the read is stored, all depending on the order of operations executed.
intare atomic. In fact, in practice, writes tolongare atomic too - but not guaranteed to be. So the write is atomic, but not visible.