This question already has an answer here: Why volatile is not working properly 6 answers I have read in almost all the posts that volatile (even if it's not static) variable is shared among the the threads. When one thread updates the variable then s
How do I pass a volatile array into a function in c++? volatile uint8_t* array[16]; void processArray(const uint8_t** inputArray) <--- ???? { // process each element in the array } void main() { processArray(array); <-- ??? } --------------Solu
I am making embedded firmware where everything after initialization happens in ISRs. I have variables that are shared between them, and I am wondering in which cases they need to be volatile. I never block, waiting for a change in another ISR. When c
This question already has an answer here: Why does std::cout convert volatile pointers to bool? 4 answers Consider this (artificial) example: #include <cstdio> #include <iostream> int main() { volatile char test[] = "abc"; std::printf("%s
I have a case when I want to avoid defensive copies, for data which might nevertheless be modified, but is usually simply read, and not written to. So, I'd like to use immutable objects, with functional mutator methods, which is kind of usual (java l
I'm looking for a creative solution for making sure that variables delivered to a specific macro are declared with type volatile in C language, with TMS470 compiler. meaning: good method: volatile int *_p_reg; VOLATILE_MACRO(_p_reg); compilation fail
I am a novice when it comes to concurrency and unsure of myself when spotting issues, I was looking through a fairly established code base and found the following code (edited for brevity) which I believe to be susceptible to data races: public class
I saw an example with session counter in Sun's "Core Servlets and JavaServer Pages vol 2". Counter is simply build on HttpSessionListener and increments/decrements session count with sessionCreated/sessionDestroyed: public class SessionCounter implem
In the new Java memory model, any write to a variable is guaranteed to be completed before the next thread read it. I wonder if this is also the case for variables that are member of this object. for java memory model: http://www.cs.umd.edu/~pugh/jav
In his excellent treatise on threading in C#, Joseph Albahari proposed the following simple program to demonstrate why we need to use some form of memory fencing around data that is read and written by multiple threads. The program never ends if you
Given the following class: class MyClass { public: int value() const { return value_; } private: volatile int value_; }; Does the value() member function also have to be marked as volatile to avoid getting optimized away or is it okay as written? Tha
Possible Duplicate: When exactly do you use the volatile keyword in Java? When and why volatile modifier is required in java? I am interested in seeing a real world usage of a volatile modified primitive or object reference. --------------Solutions--
This question already has an answer here: Why make a method volatile in java? 6 answers This one is weird. I have the following code: class A { protected A clone() throws CloneNotSupportedException { return (A) super.clone(); } } when I de-compiled i
I have a thread that spins until an int changed by another thread is a certain value. int cur = this.m_cur; while (cur > this.Max) { // spin until cur is <= max cur = this.m_cur; } Does this.m_cur need to be declared volatile for this to work?
The fallowing clause is taken from jetbrains.net After reading this and some other articles on the web, I still don't understand how is it possible to return null, after the first thread go in to the lock. Some one that does understand it can please
I'm trying to write a wrapper function for read() system call , using asm volatile , but it won't work , since the res doesn't change its value . Here's the code : ssize_t my_read(int fd, void *buf, size_t count) { ssize_t res; __asm__ volatile( "int
This question looks similar to Should my Scala actors' properties be marked @volatile? but not sure that answer will be the same. As example, in case when the fork-join dispatcher was configured and actor's state wasn't marked by @volatile, is it gua
I found this in a multi-threaded c application. The authors commented that it's used to make a thread crash in a custom assert function. GCC is fine with it, but clang issues the following warning: note: consider using __builtin_trap() or qualifying
Is it the correct behaviour or is it a quirk of g++4.5 that this code prints 1? #include <iostream> #include <typeinfo> using namespace std; int main(){ struct A{}; cout<<(typeid(A)==typeid(const A)&&typeid(A)==typeid(const
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: stati