Computer Science, asked by TransitionState, 11 months ago

Threads accessing same variable at same time. How on processor level they are assigned value

Answers

Answered by preranaupadhyay742
0

Basically it's true, but actually the problem is more complex. Visibility of shared data can be affected not only by CPU caches, but also by out-of-order execution of instructions.

Therefore Java defines a Memory Model, that states under which circumstances threads can see consistent state of the shared data.

In your particular case, adding volatile guarantees visibility.

Answered by indiabrainly
0

Answer:

Explanation:

Static variables are shared between thread. However, you must know that any change in one thread mat not be visible in another thread. It may appear that that there are two copies of the variable.

Every Java thread works in separate memory space.Java process run in single process and not in multiple processes. But, yes, it does uses multiple processes for multiple threads.

Similar questions