Skip to main content

Questions tagged [happens-before]

Happens-before relates to multi-threading applications where logic has happened before a sequence of thread logic has occurred.

happens-before
1 vote
1 answer
46 views

Possible contradiction between happens-before relationship and out-of-order execution in a single thread

I'm reading Rust Atomics and Locks (O'Reilly Media, Inc.). In Chapter 3. Memory Ordering, it first says Processors and compilers perform all sorts of tricks to make your programs run as fast as ...
ynn's user avatar
  • 4,351
0 votes
1 answer
52 views

Java happens-before relationship for listener implementation

Consider the following part of a Java application final List<String> strings = new CopyOnWriteArrayList<>(); volatile Consumer<? super String> listener; void add(String s) { ...
stonar96's user avatar
  • 1,452
0 votes
2 answers
72 views

Is the Happens-Before mechanism only hb(w, r)?

I'm trying to understand the Happens Before mechanism and i can't find any source in the internet talking about happens-before relationship between a READ and subsequent WRITE. I can only read about ...
Unearthly's user avatar
  • 149
0 votes
2 answers
103 views

JMM specification example

I've read 17.4.5 article of Jmm spec and I have a question about this example. Thread 1; Thread 2; B = 1; A = 2; r2 = A; r1 = B; Authors write that r2 and r1 can be equal to 0 because of ...
Роман Григорьев's user avatar
1 vote
0 answers
46 views

Is weakCompareAndSet's "Spurious failure" simply the presence of contention in the LOCK prefix? [duplicate]

I've seen the argument that the reson why it is named "weak", is because the "strong" version has happens-before "orderings" behavior. In my understanding "Happens ...
Delark's user avatar
  • 1,221
1 vote
2 answers
104 views

Java volatile and happens-before

There is what java spec says about it: https://docs.oracle.com/javase/specs/jls/se8/html/jls-17.html#jls-17.4.5 "A write to a volatile field (§8.3.1.4) happens-before every subsequent read of ...
RedMurloc's user avatar
  • 127
0 votes
1 answer
52 views

I checked with jconsole and found there is not dead lock,but program does not exit

{static int x; public static void main(String[] args) { Thread t2 = new Thread(()->{ while(true) { if(Thread.currentThread().isInterrupted()) { ...
dun mao's user avatar
0 votes
1 answer
58 views

Writing to a volatile field and reading another volatile field: Is the happens-before-rule valid?

Question: Is this statement true: „A write to a volatile field happens-before every subsequent read of that or another volatile field.“ On How to understand happens-before consistent I found the ...
dibo's user avatar
  • 1
1 vote
3 answers
156 views

Happens-Before Relationship - What is an atomic object talking about concurrency in C++?

https://timsong-cpp.github.io/cppwp/n4861/intro.races#8 An evaluation A is dependency-ordered before an evaluation B if (8.1) A performs a release operation on an atomic object M, and, in another ...
user avatar
1 vote
2 answers
181 views

Establish a release atomic ordering on an atomic object without writing into it

I'm using Rust, but Rust implements the C++ atomic memory model, so I will present my question in C++. I have an atomic object M. I want to issue an pseudo load/store operation on M, so that the store ...
Chayim Friedman's user avatar
1 vote
2 answers
193 views

Thread-safety of int field in Java

If class has field with int type (not Atomic Integer and without volatile keyword) and all access to this field happens under read/write locks - will this field thread-safe in this case? Or in some ...
dallin_sh's user avatar
8 votes
1 answer
207 views

How are the final multi-threading guarantees and the memory model related in Java?

The memory model is defined in 17.4. Memory Model. The final field multi-threading guarantees are given in 17.5. final Field Semantics. I don't understand why these are separate sections. AFAIK both ...
poq's user avatar
  • 81
16 votes
3 answers
614 views

Does Java allow a volatile read to be optimized away if the value isn't needed, also removing the happens-before synchronization?

The following code sample shows a common way to demonstrate concurrency issues caused by a missing happens-before relationship. private static /*volatile*/ boolean running = true; public static ...
stonar96's user avatar
  • 1,452
1 vote
1 answer
109 views

Does the semantics of java volatile guarantee that wrong results will not appear? (Two threads write first and then read)

volatile x=y=0 Thread1 x=1 r1=y Thread2 y=1 r2=x r1 and r2 are local variables Question1: Is the result of r1==r2==0 illegal and does not appear? All statements are writing or reading volatile ...
Joseph's user avatar
  • 141
5 votes
4 answers
636 views

Can release+acquire break happens-before?

Many programming languages today have happens-before relation and release+acquire synchronization operations. Some of these programming languages: C/C++11: happens-before, release+acquire Rust and ...
user avatar

15 30 50 per page
1
2 3 4 5
8