Questions tagged [interlocked]

Provides atomic operations for variables that are shared by multiple threads.

Provides atomic operations for variables that are shared by multiple threads.

References

233 questions
0
votes
0 answers

What is the best way to access an integer value from multiple threads?

I'm confused about how to choose the most effective way to synchronize multi threads. Supposed we have an integer value i to synchronize. 1-Write/1-Read : just simply ignore it or add volatile before i? 1-Write/N-Read : just simply ignore it or add…
0
votes
2 answers

Interlocked & Thread-Safe operations

1. Out of curiosity, what does operations like the following do behind the scenes when they get called for example from 2 or 3 threads at the same time? Interlocked.Add(ref myInt, 24); Interlocked.Increment(ref counter); Does the C# creates an…
Robert
  • 13
  • 5
0
votes
0 answers

Shared resource single thread writing, multiple thread reading using interlock

I'm trying to implement single thread writing, multiple thread reading mechanism for shared resource management using interlock in C++, windows environment. Q1. The result code seems to work as what I intend, but I'd like to ask for your wisdom if I…
YoonSeok OH
  • 647
  • 2
  • 7
  • 15
0
votes
1 answer

How to remove / reduce too many repetitive InterlockedCompareExchange?

I've learned that InterlockedCompareExchange() is used to read interlocked variables. Also, InterlockedCompareExchange() is preferable rather than InterlockedOr() by Raymond Chen from the comments of reference: Reading interlocked…
YoonSeok OH
  • 647
  • 2
  • 7
  • 15
0
votes
2 answers

Given an external producer API that can be stopped and started, efficiently stop the producer when local buffer is full

Suppose I am provided with an event producer API consisting of Start(), Pause(), and Resume() methods, and an ItemAvailable event. The producer itself is external code, and I have no control over its threading. A few items may still come through…
allmhuran
  • 4,154
  • 1
  • 8
  • 27
0
votes
1 answer

Unique integer multiple threads

I am trying to generate unique integer Ids that can be used from multiple threads. public partial class Form1 : Form { private static int sharedInteger; ... private static int ModifySharedIntegerSingleTime() { int unique =…
Ivan
  • 7,448
  • 14
  • 69
  • 134
0
votes
1 answer

C# Max counter with Interlocked

I've been given an assignment to write a max counter class with the following contract: class MaxCounter { private int _value = int.MinValue; public void Max(int value) { if(value > _value) { _value = value; } } public int…
Gilbert Williams
  • 970
  • 2
  • 10
  • 24
0
votes
2 answers

Interlocked functions c++

I am developing a system that uses shared memory and interlocked functions. Let's assume i have volatile unsigned int n, a, b. I want to do the following pseudocode atomicly: if (a <= n && n < b) { n++; } else { //Do nothing } How would I…
sigvardsen
  • 1,531
  • 3
  • 26
  • 44
0
votes
1 answer

Using Interlocks for thread synchronization and maintaining cache coherency

If I were to use some kind of algorithm that uses InterlockCompareExchange operations on a variable in C++ that determines if a set of data is being written to by a particular thread (by creating my own little lock), how do I ensure that the…
contrapsych
  • 1,919
  • 4
  • 29
  • 44
0
votes
1 answer

Intelocked.Exchange instead of ReaderWriterLockSlim

In a multithreaded application, I have a Dictionary that is accessed by multiple threads for gettinng the value for a specific key. There is also a mechanism using Quartz.Net to update this dictionary. I am trying to find the best way to make the…
fdhsdrdark
  • 144
  • 1
  • 13
0
votes
0 answers

C# interlocked decrement on short value

I am doing some experimentation, and I need to atomically decrement a 16-bit (short) value in C#. The value is stored in unmanaged memory, and it is not a problem to ensure the value is aligned to a 16-bit virtual memory boundary. I found that…
DEHAAS
  • 1,294
  • 11
  • 17
0
votes
2 answers

Wait until a variable becomes zero

I'm writing a multithreaded program that can execute some tasks in separate threads. Some operations require waiting for them at the end of execution of my program. I've written simple guard for such "important" operations: class…
Georgy Firsov
  • 286
  • 1
  • 13
0
votes
2 answers

How to turn on one of the toggle buttons

I want the other toggle button to turn off when one turns on. This is my togglebutton's xml code This code is made in…
josungwoo
  • 13
  • 3
0
votes
1 answer

Within Parallel.ForEach loop, I want to increment a var but Interlock.Increment doesn't seem to work

I've got a process that takes a long time so I want to break it out into Threads. My threading approach works fine with Parallel.ForEach, only I want to inform a user how many of the variable number of items we've processed so far. Here's a…
FoxDeploy
  • 12,569
  • 2
  • 33
  • 48
0
votes
0 answers

Listen on variable change in kernel thread with performance

This question is a continuation of a previously asked question: Slow communication using shared memory between user mode and kernel I am running a thread in the Windows kernel communicating with an application over shared memory. I am wondering if…
illion
  • 31
  • 1
  • 7