non-volatile

Assign volatile to non-volatile sematics and the C standard

浪子不回头ぞ 提交于 2021-02-18 16:14:29
问题 volatile int vfoo = 0; void func() { int bar; do { bar = vfoo; // L.7 }while(bar!=1); return; } This code busy-waits for the variable to turn to 1 . If on first pass vfoo is not set to 1 , will I get stuck inside. This code compiles without warning. What does the standard say about this? vfoo is declared as volatile . Therefore, read to this variable should not be optimized. However, bar is not volatile qualified. Is the compiler allowed to optimize the write to this bar ? .i.e. the compiler

Assign volatile to non-volatile sematics and the C standard

百般思念 提交于 2021-02-18 16:06:43
问题 volatile int vfoo = 0; void func() { int bar; do { bar = vfoo; // L.7 }while(bar!=1); return; } This code busy-waits for the variable to turn to 1 . If on first pass vfoo is not set to 1 , will I get stuck inside. This code compiles without warning. What does the standard say about this? vfoo is declared as volatile . Therefore, read to this variable should not be optimized. However, bar is not volatile qualified. Is the compiler allowed to optimize the write to this bar ? .i.e. the compiler

Assign volatile to non-volatile sematics and the C standard

拥有回忆 提交于 2021-02-18 16:06:32
问题 volatile int vfoo = 0; void func() { int bar; do { bar = vfoo; // L.7 }while(bar!=1); return; } This code busy-waits for the variable to turn to 1 . If on first pass vfoo is not set to 1 , will I get stuck inside. This code compiles without warning. What does the standard say about this? vfoo is declared as volatile . Therefore, read to this variable should not be optimized. However, bar is not volatile qualified. Is the compiler allowed to optimize the write to this bar ? .i.e. the compiler

Cannot override a type with non-volatile upper bound

﹥>﹥吖頭↗ 提交于 2019-12-20 20:12:06
问题 I have a compiler error in scala and I don't know what does it refer to: Assume these declarations: trait Abstract { type MyType } trait AInner trait A extends Abstract{ type MyType <: AInner } trait BInner { def bMethod : Int } trait B extends Abstract with A{ override type MyType <: BInner with A#MyType } What I'm trying to achieve here(in trait B ) is to further restrict the type MyType declared in Abstract , so any value of type MyType must extend all the MyType s in the mixin tree. The

Volatile Pointer to Non Volatile Data

冷暖自知 提交于 2019-12-08 03:31:03
问题 Suppose I have the following declaration: int* volatile x; I believe that this defines a volatile pointer "normal" variable. To me this could mean one of two things: First Guess The pointer can change, but the number will not change without notice. This means that some other thread (that the compiler doesn't know about) can change the pointer, but if the old pointer was pointing to a "12" then the new pointer (the new value of the pointer, because the thread changes it) would point to another

Cannot override a type with non-volatile upper bound

人盡茶涼 提交于 2019-12-03 07:25:23
I have a compiler error in scala and I don't know what does it refer to: Assume these declarations: trait Abstract { type MyType } trait AInner trait A extends Abstract{ type MyType <: AInner } trait BInner { def bMethod : Int } trait B extends Abstract with A{ override type MyType <: BInner with A#MyType } What I'm trying to achieve here(in trait B ) is to further restrict the type MyType declared in Abstract , so any value of type MyType must extend all the MyType s in the mixin tree. The compiler is giving me this message(as in title): type MyType is a volatile type; cannot override a type

Does JVM guarantee to cache not volatile variable?

六月ゝ 毕业季﹏ 提交于 2019-12-02 12:50:28
问题 Does JVM guarantee to cache not volatile variable ? Can a programer depend upon on JVM to always cache non-volatile variables locally for each thread. Or JVM may or may not do this, thus a programer should not depend upon JVM for this. Thanks for the answers in advance. 回答1: No. The JVM doesn't guarantee "caching" of non-volatile fields. What implementations of JVM guarantee is how volatile fields should behave . Caching of fields is non-standard (unspecified) and can vary from JVM to JVM

Does JVM guarantee to cache not volatile variable?

牧云@^-^@ 提交于 2019-12-02 04:34:44
Does JVM guarantee to cache not volatile variable ? Can a programer depend upon on JVM to always cache non-volatile variables locally for each thread. Or JVM may or may not do this, thus a programer should not depend upon JVM for this. Thanks for the answers in advance. No. The JVM doesn't guarantee "caching" of non-volatile fields. What implementations of JVM guarantee is how volatile fields should behave . Caching of fields is non-standard (unspecified) and can vary from JVM to JVM implementation. So, you shouldn't really rely on it (even if find out, by some way that some data is being