Volatile is a qualifier used to define a data storage area (object, field, variable, parameter) that "can change on its own", thus disallowing some code generator optimizations. In some but not all languages that recognize this qualifier the access to such data is thread safe.

learn more…| top users | synonyms

1
vote
0answers
54 views

Volatile keyword is not taking effect

I am programing a TI TM4C microcontroller and stuck with some unusual behavior where volatile is not working as I expect it.I expect the volatile keyword to work such that any reads or writes ...
1
vote
0answers
58 views

why java program runs perfectly even without using volatile variable? [duplicate]

I know very well what volatile variable is, but, I have never seen any setup that failed, if volatile is not used. As per the accepted answer's case in thread(Do you ever use the volatile keyword in ...
4
votes
2answers
223 views

Usefulness of volatile in concurrent programming since C++11

I've read this and this answer. I've also searched the book C++ Concurrency in Action and found no discussion about volatile nor any example using it. Looks like it's not designed for concurrency at ...
1
vote
1answer
54 views

Accessing volatile varibales concurrently in java

While reading this blog post I'm failing to understand section 3.6 and 3.7.Code in 3.6:@JCStressTest@Statepublic class AcquireOrderWrong {int x;volatile int g;@Actorpublic ...
-2
votes
0answers
10 views

Where to find most intraday volatile stocks / ETFs / indices

does anybody know a good website, tool or scanner to find the most intraday volatile financial Instruments such es stocks / ETFs / Indices ?
0
votes
2answers
112 views

Can using volatile with “AtomicInteger” guarantees thread safety?

Suppose I have private volatile AtomicInteger atomInt=new AtomicInteger(3);and in methods my usage is atomInt.incrementAndGet().Since I am using AtomicInteger, it will avoid "thread ...
0
votes
0answers
26 views

Doesn't “volatile” ensure that other threads see a consistent value for the variable? [duplicate]

My understanding of "volatile" have been that changes made to a volatile variable by one thread is visible to another thread (basically all threads see a consistent value of the variable) and that ...
9
votes
2answers
532 views

Re-ordering of assignments and adding a fence

The following Java code looks a little strange because I have simplified it down to the bare essentials. I think the code has an ordering problem. I am looking at the first table in the JSR-133 ...
3
votes
6answers
120 views

Is volatile required here

I'm implementing a 'sequence lock' class to allow locked write and lock-free reads of a data structure.The struct that will contain the data contains the sequence value, which will be incremented ...
0
votes
0answers
26 views

Store some Core Data entities in SQL lite but others only in memory of same managed object type

I can't find a solution for my following case. It is about a chat implementation, where I store everything in core data to not need to download everything again every time.This means that I am ...
1
vote
2answers
58 views

Can the singleton contract be broken? If yes in how many ways?

Recently I appeared for the interview and she/he asked me the question - you have below singleton class and you have to break the singleton contract, tell me how to do that? I thought and thought ...
0
votes
1answer
48 views

volatile pointer without variable

In C, when I want to put number 5 at address 0x28, I can do it this way:char* x=(char *) 0x28;*x=5;If I want, I can do the same without declaring a variable:*((char *) 0x28)=5;If I want ...
0
votes
2answers
30 views

volatile keyword doesnt synchronize the values

Below piece of code gives me result as follows:Change listenerChange listenerChange listenerIncrementing MY_INT to:1Incrementing MY_INT to:2Got Change for MY_INT :1loc:0Change listenerChange ...
0
votes
3answers
52 views

If a thread finishes executing its last statement, as soon as that is done, is it guaranteed to dead as if explicitly calling return?

For example take this code snippet,static volatile boolean isDone=false;public static void main(String[] args) throws InterruptedException {// I know ArrayBlockingQueue cannot take 0 as the ...
6
votes
2answers
115 views

What is difference between getXXXVolatile vs getXXX in java unsafe?

I am trying to understand the two methods here in java unsafe:public native short getShortVolatile(Object var1, long var2);vspublic native short getShort(Object var1, long var2);What is ...
7
votes
1answer
117 views

Intermediate pointers in cast must be “const qualified” - why?

In the following code...#include <stdlib.h>#include <stdint.h>extern void get_buffer_from_HW_driver(volatile uint32_t **p);void getBuffer(volatile uint32_t **pp){// Write an ...
1
vote
2answers
42 views

Do I have the correct understanding of Can Reorder rules from the JSR-133 Cookbook?

In this link http://gee.cs.oswego.edu/dl/jmm/cookbook.html , there is this table that speaks about what can be reordered and cannot.Here is the imageNow take a look at this quote from http://...
2
votes
3answers
57 views

Volatile keyword atomicity

I am trying to learn volatile field modifier in multi-threading. I came across this statement:Volatile is preferred in cases when one thread reads and writes a shared variable and other threads ...
-1
votes
1answer
60 views

To what extent does volatile in java prevent compiler from reordering instructions?

Say for examplevolatile int my_volatile_value=0;// instruction 1. do something// instruction 2. do something with my_volatile_value// instruction 3. do something// instruction 4. call ...
1
vote
2answers
71 views

C++ reference to volatile object - reasons and effects

I'm working on existing C++ code that has volatile references to objectsvolatile vClass & vobj;I come from C so I'm familiar with volatile when used to access memory-mapped IO like this: *((...
1
vote
2answers
60 views

The behaviour of making a non-volatile reference to a volatile object in Java

Coming from C/C++, I am a little confused about volatile object behavior in Java. I understand that volatile in Java has two properties:Won't bring object into cache, always keep it in main memory....
2
votes
1answer
77 views

Return value of static volatile variable in C Function

Two scenarios: a function that returns the value of a static volatile variabledirect access to a volatile variableQ1: Will an assignment from a function call behave differently than assignment ...
3
votes
4answers
78 views

Java forcing volatile access

Consider a situation like this. There are two threads and a shared resource(like a HashMap). One thread created the HashMap and initialized it with some key-value pairs and after the shared resource ...
1
vote
0answers
47 views

How to Force a Function (UDF) Update in MS Excel VBA

This is my first post because in several years of learning VBA, I always been able to find the answers to all my question because some one else beat me to it and because stackexchange rocks. However, ...
0
votes
0answers
33 views

Excel - Is INDEX Volatile Here?

If the data in the range A1:C3 is this:1 2 34 5 67 8 9Then is the following formula volatile?=SUMPRODUCT(INDEX(A1,1,1):INDEX(C3,1,1))My guess is that it is volatile, since for example cell ...
0
votes
1answer
83 views

const volatile doubled in production code [duplicate]

I am currently working with production code in ANSI-C, which is partly getting generated by a very intransparent toolchain (so I could not find any clear information about it).Somewhere in the ...
-2
votes
2answers
44 views

Atomic CAS with non-volatile field

If we consider for a moment the following class and x86 architecture:class Foo{int x;void increment() {compareAndSwap(x, x+1);}int getX() { return x; }}If we now ...
1
vote
1answer
26 views

Volatile variables in Server EndPoint for WebSocket Java API?

Looking at other examples across the web, when a server endpoint is created by means of Java API for WebSocket, the shared variables among all EndPoint instances are defined as static, but not ...
1
vote
1answer
49 views

C++ How to get sizeof of parent datatype?

I have struct A that holds struct B.I want to have an int insidestruct B to hold the size of struct A ().However, struct B has avector of an unknown size that may differ at any time.The volatile...
0
votes
1answer
43 views

How to overload operators in C++ when declaring an Object as volatile

I need advice on volatile Objects. Here is my classclass A{private:volatile unsigned long count;public:A & operator=(unsigned long number) { count=number; return *this; }};I create ...
0
votes
2answers
53 views

Sum variable range : replace indirect with non volatile

I use this formula a lot in my spreadsheet :SUM(INDIRECT(ADDRESS(row(),column(B))&":"&ADDRESS(MATCH("*",INDIRECT("A"& row()+1&":A"& row()+250),0)+ row()-1,column(B))))This ...
0
votes
1answer
47 views

Is there ever a reason to use asm volatile for PTX with no side-effects?

The CUDA documentation on inline PTX, section 1.2.3 Incorrect optimization, says:The compiler assumes that an asm() statement has no side effects except to change the output operands. To ensure ...
1
vote
1answer
46 views

Publishing and reading of non-volatile field

public class Factory {private Singleton instance;public Singleton getInstance() {Singleton res=instance;if (res==null) {synchronized (this) {...
-1
votes
1answer
14 views

When I use the volatile and AtomicInteger practice found that the output should have the output of the code disappears

When I use the volatile and AtomicInteger practice found that the output should have the output of the code disappeared, I hope someone can help me solve this problemIt should have output, but the ...
1
vote
2answers
100 views

Volatile doesn't work as expected

So I'm reading Brian Goetz' JCIP and wrote a following code for experimenting with volatile behavior.public class StatefulObject {private static final int NUMBER_OF_THREADS=10;private ...
14
votes
2answers
1k views

Why is volatile not compiling with std::min

Why is following code not compilable (gcc-5.4.0)?volatile int i{100};int j{200};std::cout << std::min(i, j);I mean I see the compiler error:error: no matching function for call to ‘min(...
2
votes
2answers
90 views

Volatile variable assignment in a synchronized block results in null

here's a class:public class Refreshable<T> {private final Object lock=new Object();private final Supplier<Object>[] dynamicSettings;private final Supplier<T> ...
2
votes
0answers
51 views

In gcc is there a way to find out which symbols are being touched by the optimizer?

Very diffuse question I admit - maybe you can just give me a hint in the right direction..In a fairly large embedded C based project we observe different behavior when updating from arm-none-eabi-...
41
votes
2answers
2k views

What is the purpose of the “volatile” keyword appearing inside an array subscript?

While I was browsing cppreference, I saw a strange type array in function parameters like this:void f(double x[volatile], const double y[volatile]);So, What is the purpose of the volatile keyword ...
2
votes
1answer
37 views

viewability of a non-volatile write

Let's say I have a static int that affects behaviour of the class.class A{public static int classFlag=0;private int myFlag=0;public void doSomething(){if(myFlag !=...
1
vote
1answer
54 views

volatile in single core cpu java

(In case of single CPU ) for understanding volatile -I know volatile forces thread to use main memory and will not keep copy in its local memory. In one of the StackOverFlow post I see that java ...
2
votes
2answers
68 views

Use of volatile keyword on the flag field

I try to understand the use of volatile in multithread context. In the following code from another source of knowledge on the Internet:class Program{static string _result;//static ...
5
votes
1answer
155 views

What does `static_cast<volatile void>` mean for the optimizer?

When people are trying to perform rigorous benchmarks in various libraries, I sometimes see code like this:auto std_start=std::chrono::steady_clock::now();for (int i=0; i < 10000; ++i)for ...
2
votes
0answers
49 views

Java reordering volatile write with non-volatile

I have a question about the code segment bellow. It is possible to have a result [0, 1, 0] for the result (this is test executed with JCStress). So how this can happen? I think that the data write (...
1
vote
1answer
47 views

How to use volatile properly for thread killing purposes?

I read many "How to kill a Thread in Java" topics and found one way is to use a boolean volatile variable to indicate whether the Thread should continue running but I've not yet seen an answer that ...
1
vote
0answers
22 views

Use of volatile on function parameter [duplicate]

The following code runs a simple background process repeatedly until requested to stop by the main thread:#include <iostream>#include <thread>#include <chrono>void sleep(int ...
8
votes
2answers
160 views

Is it legal to optimize away stores/construction of volatile stack variables?

I noticed that clang and gcc optimize away the construction of or assignment to a volatile struct declared on the stack, in some scenarios. For example, the following code:struct nonvol2 {...
-1
votes
2answers
55 views

Execution of volatile instruction [duplicate]

int __attribute__ ((noinline)) mySystemCall (uint32 Exception, uint32 Parameter){ #ifdef PROCESSORX__asm__ volatile ("sc")#else__asm__ __volatile__ ("mov R0, %0; mov R1, %1; svc 0x0 " ...
0
votes
0answers
45 views

What does the string inside the volatile instruction indicate [duplicate]

`int __attribute__ ((noinline)) mySystemCall (uint32 Exception, uint32 Parameter){ #ifdef PROCESSORX__asm__ volatile ("sc")#else__asm__ __volatile__ ("mov R0, %0; mov R1, %1; ...
1
vote
1answer
80 views

Does MemoryBarrier really ensure refresh values?

Albahari in his marvelous book C# in a nutshell (a free chapter is available online), talks about how memory barrier allows us to get a "refresh" value. His example is:static void Main(){...

153050per page
angop.ao, elkhabar.com, noa.al, afghanpaper.com, bbc.com, time.com, cdc.gov, nih.gov, xnxx.com, github.com,