Skip to main content
Filter by
Sorted by
Tagged with
4 votes
4 answers
171 views

Use of volatile with Interlocked.CompareExchange

I came across this blog post by Stephen Toub, demonstrating how to implement an AsyncManualResetEvent: https://devblogs.microsoft.com/dotnet/building-async-coordination-primitives-part-1-...
Codisattva's user avatar
1 vote
2 answers
92 views

The difference between set() and setVolatile of VarHandle

public class MyClass { private volatile Object refValue; private static final VarHandle REF_VALUE_HANDLE; static { try { REF_VALUE_HANDLE = MethodHandles.lookup() ...
Photon's user avatar
  • 29
1 vote
4 answers
139 views

How to make a variable volatile in main loop but not in IR handler

I have a variable which is read from my main loop, and is both read and written from an interrupt handler. The interrupt can change the value at any time, so clearly it needs to be volatile in the ...
Jack B's user avatar
  • 121
4 votes
0 answers
123 views

Why is a volatile symbol placed differently?

When an array is declared with volatile it ends up somewhere different than without: static const char ARRAY[100]; $ nm a.elf | grep ARRAY 00010d00 t ARRAY But: static volatile const char ARRAY[100];...
Caulder's user avatar
  • 358
1 vote
1 answer
84 views

Does assigning a volatile variable to itself suppress compiler optimization in a loop?

I'm working on a delay loop in C and come across an odd case with volatile. Consider this code: void delay(unsigned int count){ volatile unsigned int timer = count; while (timer > 0){ ...
Alphin Thomas's user avatar
5 votes
2 answers
157 views

Is dereferencing a volatile null pointer value undefined behavior?

It seems unclear, but there are claims that dereferencing a nullpointer is undefined behavior: A comment by M.M. This note was in fact removed as the result of DR 1102 with the stated reasoning being ...
lucidbrot's user avatar
  • 6,301
1 vote
1 answer
85 views

Does Volatile.Read() still apply if it is nested in a getter?

Consider this code in C#: private int _backingField; public int SomeNumber => Volatile.Read(ref _backingField); public void Test_1() { var someNumber = Volatile.Read(ref _backingField); /...
user3163495's user avatar
  • 3,712
4 votes
0 answers
101 views

C#'s new "field" keyword: Are "volatile" properties now possible by calling "Volatile.Read(ref field)"?

Traditionally, using the volatile keyword on properties in C# was not possible. In other words, this was not possible: // CS0106: The modifier 'volatile' is not valid for this item public volatile int ...
user3163495's user avatar
  • 3,712
2 votes
1 answer
55 views

Can a @Volatile lateinit var be atomically initialized using a DCL pattern in Kotlin?

Consider the following DCL example written in Kotlin: @Volatile private var property: String? = null private val lock = ReentrantLock() fun singletonValue(): String { if (property == null) { ...
Bass's user avatar
  • 5,368
2 votes
2 answers
108 views

Java thread confinement with Executors.newSingleThreadExecutor()

The question is about memory visibility. I have some doubts about whether a Kotlin program like the next would be thread-safe: class MyApi { private val singleThreadExecutor = Executors....
Víctor J García Granado's user avatar
0 votes
0 answers
56 views

Are local variables always volatile? [duplicate]

Are local variables always volatile in C#? In other words, is the volatility of num the same in these two classes: public sealed class ThreadSafeObjectA { private volatile int num; public int ...
user3163495's user avatar
  • 3,712
2 votes
2 answers
53 views

volatile access through cast with volatile-qualified type

I've seen constructs like the following to write to memory-mapped I/O. *((volatile unsigned int *)0xDEADBEEF) = 0x00; But is this guaranteed to be a volatile access?1 I started to think about this ...
andiluk's user avatar
  • 68
1 vote
1 answer
65 views

Volatile and optimization with different compilation units

Please have a look at this more or less standard example that i see people use when talking about the usage of volatile in the context of embedded c++ firmware development on a baremetal target: // ...
IAmPropper's user avatar
1 vote
1 answer
103 views

Perform a function only once in a method call across multiple threads in C#

I have a class from an assembly loaded at runtime that is instantiated using reflection (and therefore using a parameter-less constructor) across multiple threads (using Channels). Each thread ...
Dan Def's user avatar
  • 1,954
4 votes
1 answer
172 views

Is volatile needed with how smart compilers are these days?

Compilers are getting smarter and smarter these days. So, is volatile needed? Compilers are smart enough to ask if we still need volatile ? I tried many scenarios and it seemed like the compiler would ...
Da Wang's user avatar
  • 196

15 30 50 per page
1
2 3 4 5
133