Linked Questions

31 votes
2 answers
7k views

What is the difference between Interlocked.Exchange and Volatile.Write? Both methods update value of some variable. Can someone summarize when to use each of them? Interlocked.Exchange Volatile.Write ...
Oleg Vazhnev's user avatar
  • 24.2k
10 votes
7 answers
717 views

I've seen some lock free implementations of stack... My question is regarding the visibility, not atomicity. For example do elements(not pointers) of lock free stack must be at most 64bit? I think so, ...
NoSenseEtAl's user avatar
  • 30.9k
16 votes
2 answers
2k views

Consider an atomic read-modify-write operation such as x.exchange(..., std::memory_order_acq_rel). For purposes of ordering with respect to loads and stores to other objects, is this treated as: a ...
Nate Eldredge's user avatar
7 votes
2 answers
792 views

EDIT/Notice: Event is now thread-safe in current F# implementation. I'm working a lot with asynchronous workflows and agents in F#. While I was going a little bit deeper into events I noticed that ...
David Raab's user avatar
  • 4,498
1 vote
4 answers
365 views

I got a book about programming in C#. There is an example. Let me copy and paste the context. ...Introduced the usage of Interlocked(omitted here). You can also use the CompareExchange method. ...
Hui Zhao's user avatar
  • 675
7 votes
1 answer
2k views

As per this question's answer, it seems that LOCK CMPXCHG on x86 actually causes a full barrier. Presumably, this is what Unsafe.compareAndSwapInt() generates under the hood as well. I am struggling ...
Bober02's user avatar
  • 15.4k
4 votes
2 answers
411 views

It looks like the mono implementation has no MemoryBarrier calls inside the ReaderWriterLockSlim methods. So when I make any changes inside a write lock, I can receive old cached values in another ...
Vlad's user avatar
  • 3,201
9 votes
2 answers
612 views

Trying to understand .net's memory model when it comes to threading. This question is strictly theoretical and I know it can be resolved in other ways such as using a lock or marking _task as volatile....
Tsef's user avatar
  • 1,038
2 votes
1 answer
412 views

I have a program which is occasionally malfunctioning and I'm wondering whether the problems might be related to different threads running on different cores handling reads and writes in a different ...
supercat's user avatar
  • 82k
-1 votes
2 answers
165 views

Does memory barrier ensure data coherence across threads when there is no locking and no concurrent data access except from the parent thread ? Here is my scenario : the Main thread launch several ...
Toto's user avatar
  • 7,739
2 votes
2 answers
171 views

Suppose you have a property public Foo Bar { get; } that you want to lazily initialize. One such approach might be to use the Interlocked class, which guarantees atomicity for certain sequences of ...
James Ko's user avatar
  • 34.9k
-1 votes
1 answer
188 views

Given a scenario where there's a function that should only be executed by one thread at any given time, and the rest just return (since a specific state is already being worked on), what's the best ...
Dennis19901's user avatar
0 votes
0 answers
133 views

I see following code in C# usage of InterLocked: class MyObj { // some class code .. int myVal public void foo() { int currVal = 0, newVal = 0; do { ...
Ashish Negi's user avatar
  • 5,321