volatile

Why does Unsafe.fullFence() not ensuring visibility in my example?

北城以北 提交于 2021-02-05 07:09:47
问题 I am trying to dive deep into volatile keyword in Java and setup 2 testing environments. I believe both of them are with x86_64 and use hotspot. Java version: 1.8.0_232 CPU: AMD Ryzen 7 8Core Java version: 1.8.0_231 CPU: Intel I7 Code is here: import java.lang.reflect.Field; import sun.misc.Unsafe; public class Test { private boolean flag = true; //left non-volatile intentionally private volatile int dummyVolatile = 1; public static void main(String[] args) throws Exception { Test t = new

Why does Unsafe.fullFence() not ensuring visibility in my example?

橙三吉。 提交于 2021-02-05 07:03:09
问题 I am trying to dive deep into volatile keyword in Java and setup 2 testing environments. I believe both of them are with x86_64 and use hotspot. Java version: 1.8.0_232 CPU: AMD Ryzen 7 8Core Java version: 1.8.0_231 CPU: Intel I7 Code is here: import java.lang.reflect.Field; import sun.misc.Unsafe; public class Test { private boolean flag = true; //left non-volatile intentionally private volatile int dummyVolatile = 1; public static void main(String[] args) throws Exception { Test t = new

Java JIT compiler optimizations - is JIT consistent in respect to volatile variables value caching?

泪湿孤枕 提交于 2021-01-28 04:23:35
问题 I'm trying to better understand how does the JIT compiler work for java in respect to volatile variable value caching. Consider the example presented in this question: Infinite loop problem with while loop and threading: boolean loaded = false; // not volatile!!! private boolean loadAsset() { new Thread(new Runnable() { @Override public void run() { // Do something loaded = true; } }).start(); while (!loaded) { System.out.println("Not Loaded"); } System.out.println("Loaded"); return false; }

Optimizing huge value list in Teradata without volatile tables

拜拜、爱过 提交于 2021-01-28 04:11:30
问题 Have a value list like` `where a.c1 in ( list ) ` Then shoving the list in the volatile table is the best way out. However this is being done via cognos & IBM isn't smart enough to know what Teradata's volatile table is. I wish It was so I could use exclusion logic Exists to go through the volatile table contents. So without volatile table , I have a value list where a.c1 in ( list ) which has like 5K values. Keeping that list in the report is proving expensive. I wondered if it was possible

Is marking String type reference as Volatile safe?

半城伤御伤魂 提交于 2021-01-27 08:00:59
问题 I've read some posts and articles saying that we shouldn't declare java objects as volatile, because as a result, only the reference becomes volatile. Here are some examples: link-1 link-2 link-3 What Sonar suggests is 'Non-primitive fields should not be "volatile"', however, it also suggests that the problem described refers to mutable objects 'Similarly, marking a mutable object field volatile means the object reference is volatile but the object itself is not'. My question is: is it safe

Is marking String type reference as Volatile safe?

怎甘沉沦 提交于 2021-01-27 07:56:53
问题 I've read some posts and articles saying that we shouldn't declare java objects as volatile, because as a result, only the reference becomes volatile. Here are some examples: link-1 link-2 link-3 What Sonar suggests is 'Non-primitive fields should not be "volatile"', however, it also suggests that the problem described refers to mutable objects 'Similarly, marking a mutable object field volatile means the object reference is volatile but the object itself is not'. My question is: is it safe

Volatile variable in class: “expected unqualified-id before 'volatile'”?

。_饼干妹妹 提交于 2021-01-27 06:52:51
问题 I have two static volatile variables defined in my class ADC . The class is written as: (cropped to save space) #pragma once #include "../PeriodicProcess/PeriodicProcess.h" #include <stdint.h> #include <stdlib.h> class ADC { private: static inline unsigned char SPI_transfer(unsigned char data); void read(uint32_t tnow); static const unsigned char adc_cmd[9]; static volatile uint32_t _sum[8]; static volatile uint16_t _count[8]; public: ADC(); void raw(); void init(PeriodicProcess * scheduler);

Are volatile variables useful? If yes then when?

不问归期 提交于 2021-01-21 06:34:31
问题 Answering this question made me think about something is still not clear for me. Let's first assume we read all from this post and this post. [begin edit] Maybe it's not so obvious (Italian humor?!) but title is just pretty provocative : of course there should be a reason if volatile has been included in C#, I just can't understand exact one. [end edit] In short we know we have three tools to share a variable between threads: lock because this will prevent instruction reordering. volatile

Java, volatile and memory barriers on x86 architecture

狂风中的少年 提交于 2021-01-02 07:18:52
问题 This is more of a theoretical question. I'm not sure if all concepts, compiler behaviors, etc. are uptodate and still in use, but I'd like to have confirmation if I'm correctly understanding some concepts I'm trying to learn. Language is Java. From what I've understood so far, on X86 architecture, StoreLoad barriers (despite the exact CPU instructions used to implement them) are put after Volatile writes, to make them visible to subsequent Volatile Reads in other threads (since x86 doesn't

Java, volatile and memory barriers on x86 architecture

流过昼夜 提交于 2021-01-02 07:18:22
问题 This is more of a theoretical question. I'm not sure if all concepts, compiler behaviors, etc. are uptodate and still in use, but I'd like to have confirmation if I'm correctly understanding some concepts I'm trying to learn. Language is Java. From what I've understood so far, on X86 architecture, StoreLoad barriers (despite the exact CPU instructions used to implement them) are put after Volatile writes, to make them visible to subsequent Volatile Reads in other threads (since x86 doesn't