happens-before

Java happens-before relationship invokeAndWait

天涯浪子 提交于 2021-02-07 09:07:40
问题 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 actions on the EDT of the runnable thereby submitted. My question is a bit more general: Is it even possible to implement a method, such as invokeAndWait , such that it works properly , but not imposing a happens-before relationship? By the method working properly I mean the following: The submitted

Java happens-before relationship invokeAndWait

社会主义新天地 提交于 2021-02-07 08:58:56
问题 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 actions on the EDT of the runnable thereby submitted. My question is a bit more general: Is it even possible to implement a method, such as invokeAndWait , such that it works properly , but not imposing a happens-before relationship? By the method working properly I mean the following: The submitted

Java happens-before relationship invokeAndWait

血红的双手。 提交于 2021-02-07 08:57:21
问题 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 actions on the EDT of the runnable thereby submitted. My question is a bit more general: Is it even possible to implement a method, such as invokeAndWait , such that it works properly , but not imposing a happens-before relationship? By the method working properly I mean the following: The submitted

“Partial Ordering” and Happens-before relation java

ぐ巨炮叔叔 提交于 2020-02-01 03:24:06
问题 I am reading Java Concurrency in Practice I am confused with the specific explanation regarding happens-before relationship. It states that, operations are ordered by a partial ordering called happens-before What exactly does this mean by "partial ordering" ? (There is an explanation in the book but its not clear to me ) 回答1: Partial Ordering means that not every pair of operations has the relation happens-before . Actually, the fact that not every pair of operations has that relation enables

Java's happens-before and synchronization

China☆狼群 提交于 2020-01-01 00:22:39
问题 I'm having a little disagreement on Java's happens-before and synchronization. Imagine the following scenario: Main Thread MyObject o = new MyObject(); // (0) synchronized (sharedMonitor) { // (1) add the object to a shared collection } // (2) spawn other threads Other Threads MyObject o; synchronized (sharedMonitor) { // (3) retrieve the previously added object } // (4) actions to modify the object Note that the instance variables of MyObject aren't neither volatile , nor final . The methods

Does pthread_mutex_lock have happens-before semantics

限于喜欢 提交于 2019-12-25 04:42:12
问题 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_mutex_lock(&b_mutex) ... pthread_mutex_unlock(&b_mutex) } // 3 int tmp = global_a; // 4 } and suppose that from an observer view the execution sequence indeed is threadA --- 1 threadA --- 2 threadB --- 3 threadB --- 4 Can the code at threadB "int tmp = global_a;" see what threadA set at "global_a = 100;" ? Any suggestion

How does a Java virtual machine implement the “happens-before” memory model?

…衆ロ難τιáo~ 提交于 2019-12-22 05:58:22
问题 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 example in the following case: // thread A private void method() { //code before lock synchronized (lockA) { //code inside } } // thread B private void method2() { //code before lock synchronized (lockA) { //code inside } } // thread B private void method3() { //code before lock synchronized (lockB) { /

Happens-Before relation in Java Memory Model

给你一囗甜甜゛ 提交于 2019-12-19 02:52:28
问题 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 "ordered before"? Because even if action_a happens-before action_b, action_a can be executed after action_b in some implementation, right? (2) If action_a happens-before action_b, does it mean action_a MUST NOT see action_b? Or action_a may see or may not see action_b? (3) If action_a does NOT happen

How deep volatile publication guarantees?

时光总嘲笑我的痴心妄想 提交于 2019-12-18 11:13:18
问题 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: class Foo{ private final Map map; Foo(){ map = new HashMap(); map.put(1,"object"); } public void bar(){ System.out.println(map.get(1)); } } As I undertand at this case we have guarantee that bar() method always output object because: 1. I listed full code of class Foo and map is final; 2. If some

How deep volatile publication guarantees?

微笑、不失礼 提交于 2019-12-18 11:13:15
问题 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: class Foo{ private final Map map; Foo(){ map = new HashMap(); map.put(1,"object"); } public void bar(){ System.out.println(map.get(1)); } } As I undertand at this case we have guarantee that bar() method always output object because: 1. I listed full code of class Foo and map is final; 2. If some