interlocked Questions
6
Solved
I'm trying to use Interlocked.CompareExchange with this enum:
public enum State {
Idle,
Running,
//...
}
The following code doesn't compile, but that's what I want do do:
if (Interlocked.Com...
Finagle asked 21/8, 2013 at 13:17
5
Solved
Can I use an Interlocked.* synchronization method to update a DateTime variable?
I wish to maintain a last-touch time stamp in memory. Multiple http threads will update the last touch DateTime vari...
Congest asked 7/10, 2009 at 13:31
4
Solved
If many threads are calling GetNextNumber simultaneously with the following code, GetNextNumber will return 1 more times than any other numbers.
private class RoundRobbinNumber
{
private int _max...
Narcotism asked 5/4, 2012 at 18:51
6
Solved
(This is a repeat of: How to correctly read an Interlocked.Increment'ed int field? but, after reading the answers and comments, I'm still not sure of the right answer.)
There's some code that ...
Padre asked 17/7, 2014 at 15:56
2
Solved
What is the difference, if any, of the Read(Int64) method of the .NET system classes System.Threading.Volatile and System.Threading.Interlocked?
Specifically, what are their respective guarantees ...
Triangle asked 15/8, 2019 at 9:17
3
Solved
While I was reading about ReaderWriterLockSlim lock mechanism , There was this guy who suggested that Interlock Functions can be used for a finer locking
Also, I found here another answer from Mar...
Tibiotarsus asked 24/5, 2014 at 8:31
2
Solved
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.Wr...
Product asked 14/9, 2012 at 13:37
10
Solved
Let's say that a class has a public int counter field that is accessed by multiple threads. This int is only incremented or decremented.
To increment this field, which approach should be used, and...
Nelsonnema asked 30/9, 2008 at 19:25
7
I came across a ConcurrentDictionary implementation for .NET 3.5 (I'm so sorry I could find the link right now) that uses this approach for locking:
var current = Thread.CurrentThread.ManagedThrea...
Corroboree asked 27/12, 2013 at 12:44
2
I came across some odd performance results when optimizing a program, which are shown in the following BenchmarkDotNet benchmark:
string _s, _y = "yo";
[Benchmark]
public void Exchange() => In...
Ladanum asked 26/1, 2018 at 21:51
2
Solved
Below is an implementation of an interlocked method based on Interlocked.CompareExchange.
Is it advisable for this code to use a SpinWait spin before reiterating?
public static bool AddIfLessThan...
Rackrent asked 4/11, 2019 at 15:6
2
Solved
The docs for Interlocked.Exchange<T> contain the following remark:
This method overload is preferable to the Exchange(Object, Object) method overload, because the latter requires late-boun...
Petal asked 16/8, 2019 at 16:7
3
Solved
How do I modify an int atomically and thread-safely in Java?
Atomically increment, test & set, etc...?
Funds asked 20/7, 2009 at 8:25
3
I was looking for a thread-safe counter implementation using Interlocked that supported incrementing by arbitrary values, and found this sample straight from the Interlocked.CompareExchange documen...
Cladding asked 26/9, 2011 at 14:33
3
Solved
I just found out about the Interlocked class and now I have some basic questions.
From my understanding I should use Interlocked when manipulating numeric variables when multi-threading. If that st...
Elater asked 7/5, 2013 at 13:24
5
Solved
Suppose I have a variable "counter", and there are several threads accessing and setting the value of "counter" by using Interlocked, i.e.:
int value = Interlocked.Increment(ref counter);
and
i...
Moxley asked 5/2, 2009 at 17:10
2
Solved
Is there any way to use the Interlocked.CompareExchange(); and Interlocked.Increment(); methods against values stored in a memory-mapped file?
I'd like to implement a multi-threaded service that w...
Grettagreuze asked 11/10, 2011 at 20:24
6
Solved
I have a bit of my game which looks like this:
public static float Time;
float someValue = 123;
Interlocked.Exchange(ref Time, someValue);
I want to change Time to be a Uint32; however, when I ...
Horsa asked 12/7, 2009 at 20:6
2
Solved
I have a frustrating problem with a bit of code and don't know why this problem occurs.
//
// .NET FRAMEWORK v4.6.2 Console App
static void Main( string[] args )
{
var list = new List<string...
Ironworks asked 4/4, 2017 at 12:6
1
Solved
TL;DR: I need the Microsoft C (not C++) equivalent of C11's atomic_load. Anyone know what the right function is?
I have some pretty standard code which uses atomics. Something like
do {
bar = at...
Guttle asked 7/3, 2017 at 23:11
1
Solved
Our setup is: Asp.NET + MVC5 using AutoFac for DI.
We have a class (which is a singleton) which is managing the access tokens for a variety of services. Every now and then, these tokens get too cl...
Knudsen asked 28/2, 2017 at 17:43
7
Solved
The System.Threading.Interlocked object allows for Addition (subtraction) and comparison as an atomic operation. It seems that a CompareExchange that just doesn't do equality but also GreaterThan/L...
Melodiemelodion asked 24/10, 2012 at 2:10
3
Solved
System.Threading.Interlocked.CompareExchange operator provides atomic (thus thread-safe) C# implementation of the Compare-And-Swap operation.
For example int i = 5; Interlocked.CompareExchange(re...
Sciamachy asked 14/7, 2011 at 8:23
10
Assume:
A. C++ under WIN32.
B. A properly aligned volatile integer incremented and decremented using InterlockedIncrement() and InterlockedDecrement().
__declspec (align(8)) volatile LONG _Serve...
Grampus asked 23/4, 2009 at 1:44
1
Solved
The MSDN documentation for Interlocked.Increment states:
This method handles an overflow condition by wrapping: if location = Int32.MaxValue, location + 1 = Int32.MinValue. No exception is throw...
Spheroid asked 22/2, 2016 at 16:29
1 Next >
© 2022 - 2024 — McMap. All rights reserved.