#Visibility and happens before guarantee

1 messages · Page 1 of 1 (latest)

oblique bolt
#

So I've watched video by Jakob Jenkov about Java synchronized keyword and blocks and methods. What it states is that:

Volatile happens before guarantee syays that any write to a field or variable that happens before write to a volatile variable are guaranteed to remain before writing to a volatole variable, so none of the instructions can be reordered to happen after the volatile variable.
Similarly any read of a variable that is read before the reads of other nonvolatile or volatile variables are guaranteed to happen before any of subsequent reads.

are these valid statements? Because i've to tried to verify this with LLM's and they are saying it's wrong.

limpid merlinBOT
#

<@&987246964494204979> please have a look, thanks.

#

Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#
TJ-Bot
So I've watched video by Jakob Jenkov about Java synchronized keyword and blocks and methods. What it states is that: Volatile happens before guarantee syays that any write to a field or variable that happens before write to a volatile variable are guaran

Yes, the volatile keyword in Java provides a happens-before guarantee, ensuring that any write to a volatile variable will be visible to all threads. This can help with ensuring synchronization and visibility of data across threads.

Useful links:

spare rivet
#

yes

#

id suggest to read the wiki page for "happens-before"

#

its a topic that goes deep into cpu and vm internals and theory

#

In computer science, the happened-before relation (denoted:

    →
    
  

{\displaystyle \to \;}

) is a relation between the result of two events, such that if one event should happen before another event, the result must reflect that, even if those events are in reality executed out of order (usually to...

oblique bolt
#

Doesn't seem huge topic

spare rivet
#

it is, if u dive deep enough

#

its quite complex to figure out the correct happens-before relationships between various lines of code