Java Memory Model Flashcards

1
Q

What is a strong memory model?

A

Where all processors see exactly the same value for a given memory location at all times

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a weak memory model?

A

Where memory barriers are required to flush or invalidate the local processor cache to see writes made by other processors or make writes by this processor visible to others.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

When can a data race occur?

A

A data race occurs when a variable is read by more than one thread, and written by at least one thread, but the reads and writes are not ordered by happens-before ​ .

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Explain happens-before

A

The JMM defines a partial ordering called ​ happens-before ​ on all actions within the program. To guarantee that the thread executing action B can see the results of action A, there must be a ​ happens-before ​ relationship between A and B. In the absence of a happens before ordering between two operations, the JVM is free to reorder them as it pleases.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a correctly synchronised program

A

A correctly synchronised program is one with no data races; correctly synchronised
programs exhibit sequential consistency, meaning that all actions within the program appear to happen in a fixed, global order. See the Java Volatile Keywords Deck for more information.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the rules of JMM (Happens-before)

A
Program order rule
Monitor lock rule
Volatile Variable rule
Thread Start rule
Thread Termination rule
Interruption rule
Finalizer rule
Transitivity rule
How well did you know this?
1
Not at all
2
3
4
5
Perfectly