happens-before Questions

3

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 v...

1

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 bot...
Kaiserism asked 31/7, 2022 at 23:9

4

Solved

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...
Haughay asked 1/11, 2021 at 1:38

3

Solved

Learning golang on the way, I got a little confused when trying to understand the channel communications described in the memory model spec as below: A send on a channel happens before the cor...
Saiga asked 19/10, 2017 at 4:5

1

Solved

My question is related to this question, which already has an answer: yes, there is a happens-before relationship imposed between actions of the thread calling invokeLater/invokeAndWait and action...

2

-Thread 1- y.store (20, memory_order_release); x.store (10, memory_order_release); -Thread 2- if (x.load(memory_order_acquire) == 10) { assert (y.load(memory_order_acquire) == 20); y.store (10...
Bighorn asked 21/5, 2018 at 1:50

1

The phrase "strongly happens before" is used several times in the C++ draft standard. For example: Termination [basic.start.term]/5 If the completion of the initialization of an object w...

2

Do Kotlin coroutines provide any "happens-before" guarantees? For example, is there "happens-before" guarantee between write to mutableVar and subsequent read on (potentially) other thread in this...
Nonpartisan asked 23/10, 2019 at 8:38

3

Solved

// Thread 1 // do A x.store(1, std::memory_order_release); // operation1 // Thread 2 // do B x.store(2, std::memory_order_release); // operation2 // Thread 3 x.load(std::memory_order_acquire); //...
Meatman asked 21/2, 2019 at 12:43

5

Solved

I am currently studying for a concurrent programming exam and don't understand why the output of this program is 43. Why is x = y + 1 executed before t.start()? I also should explain which happens-...

2

Solved

I have a direct ByteBuffer (off-heap) in one thread and safely publish it to a different thread using one of the mechanisms given to me by JMM. Does the happens-before relationship extend to the na...
Triadelphous asked 1/11, 2017 at 8:38

2

Solved

I have this class where I cache instances and clone them (Data is mutable) when I use them. I wonder if I can face a reordering issue with this. I've had a look at this answer and JLS but I am stil...
Pentachlorophenol asked 5/10, 2017 at 18:44

1

Solved

As is known guarant that if we have some object reference and this reference has final field - we will see all reachable fields from final field(at least when constructor was finished) example 1: ...
Untie asked 2/2, 2017 at 21:31

1

Let's say I have two threads running like this: Thread A which performs computation while updating pixels of a shared image Thread B periodically reads the image and copies it to the screen Thr...

2

Solved

I am reading 《Understanding the JVM Advanced Features and Best practices》 that has a code segment that explains happens-before rule in java. I cannot understand. The code is below: private int val...
Hermit asked 20/8, 2016 at 8:10

1

Solved

Javadoc of Executor interface says the following: Memory consistency effects: Actions in a thread prior to submitting a Runnable object to an Executor happen-before its execution begins, perhaps...
Vanessa asked 9/1, 2016 at 22:55

1

Solved

Class Future { private volatile boolean ready; private Object data; public Object get() { if(!ready) return null; return data; } public synchronized void setOnce(Object o) { if(ready) th...

2

Java's memory model is based on "happens-before" relationship that enforces rules but also allows for optimization in the virtual machine's implementation in terms of cache invalidation. For exam...

2

Solved

Java provides a Lock object in the concurrency package that according to the documentation provides more extensive locking operations than can be obtained using synchronized methods and statements....
Barbuto asked 30/9, 2015 at 10:13

2

Solved

threadA go through this snippet { global_a = 100; // 1 { pthread_mutex_lock(&b_mutex) ... pthread_mutex_unlock(&b_mutex) } // 2 } threadB go through this snippet { { pthread_mut...
Mohammadmohammed asked 21/7, 2015 at 14:20

2

Question I've had for years: In this pseudocode, ExecutorService svc = Executors.newFixedThreadPool(3); svc.submit(new Runnable() { /* code A */ }); svc.shutdown(); if(svc.awaitTermination(...)) {...

3

Solved

I'd like to clarify how happens-before relation works with volatile variables. Let we have the following variables: public static int i, iDst, vDst; public static volatile int v; and thread A: ...

2

Regarding JLS ch17 Threads and Locks, it says "if one action happens-before another, then the first is visible to and ordered before the second"; I wonder: (1) What does it really mean by saying "...
End asked 24/12, 2014 at 12:16

1

Solved

While going through Java Concurrency in practice by Brian Goetz I encountered the following line: A data race occurs when a variable is read by more than one thread, and written by at least one...
Cule asked 5/7, 2014 at 23:18

4

While reading Java docs on Memory Consistency errors. I find points related to two actions that creates happen - before relationship: When a statement invokes Thread.start(), every statemen...
Lydia asked 27/4, 2013 at 6:2

© 2022 - 2025 — McMap. All rights reserved.