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
1 answer

Atomic Interlocked.Add taking async func as parameter

I have a case where i have to implement an addition atomically and just to save a statement - i did the below int result = Interlocked.Add(ref int source, await ComputeAsync(object someObj); public async Task ComputeAsync(object someObj) { …
Adi
  • 1
  • 4
0
votes
0 answers

Is Interlock.Add + Cast faster than single lock?

I'm looking for the better way to do Interlocked.Add(ref double, double). First Way, with Interlocked.Add(ref long, long) and some casting On a parallel loop: Interlocked.Add(ref ltotalUpSeconds, (long) (av.totalUpSeconds * 1000)); Then outside…
Pablo Honey
  • 1,074
  • 1
  • 10
  • 23
0
votes
1 answer

Why this code works and not crashing

I was learning about volatile , interlock and lock in C#, Wrote below code to print odd and even numbers without using any of these synchronization construct, I ran this code several times and always gives proper answer, using System; using…
Sandeep
  • 320
  • 2
  • 4
  • 18
0
votes
1 answer

Implementing of server in C winapi

i'm new to multi-threads and want to design server this is my current code : typedef struct Session { HANDLE handlers[2]; //HANDLE h_Send; //main session handler HANDLE h_MainHandler; HANDLE sema_MessageQ; char* UserName; …
LordTitiKaka
  • 2,087
  • 2
  • 31
  • 51
0
votes
1 answer

thread-safe variables comaprison C VS2010

threaded programming I want to write simple multi-thread app. where each thread when it open I increment (using InterlockedIncrement) member by one , and decrements it (using InterlockedDecrement) when thread finishes I know about…
LordTitiKaka
  • 2,087
  • 2
  • 31
  • 51
0
votes
3 answers

c# lock not working as expected

This class uses lock and Interlocked. Both increaseCount.with_lock.Run(); and increaseCount.with_interlock.Run(); prints between 96-100. I am expecting both of them to print always 100. What did I make mistake? public static class increaseCount { …
mustafa öztürk
  • 539
  • 3
  • 13
0
votes
3 answers

Replacing a lock with an interlocked operation

Is there anyway of replacing this code using the Interlocked.Exchange API? if (IsWorking == false) { lock (this) { if (IsWorking == false) { IsWorking = true; } } }
crazy novice
  • 1,757
  • 3
  • 14
  • 36
0
votes
0 answers

AtomicXXX.get() equivalent

In Java, AtomicInteger and AtomicLong seem to implement the same functionality as .NET's Interlocked. Additionally, they provide a get() method to read the most current value (which may differ from that stored in the CPU cache): private volatile…
Bass
  • 4,977
  • 2
  • 36
  • 82
0
votes
2 answers

Is using Interlocked in C# get and set thread safe?

Is it possible to get a thread safe property by using Interlocked in the property accessors? Example: public class A() { private static long count; public static long Count { get { return…
Ben Steeves
  • 130
  • 1
  • 10
0
votes
1 answer

Interlocked functions in Haxe

I am new to Haxe. When I try to convert the following line from C# to Haxe using CS2HX: Interlocked.Increment(ref this.fieldName); I get error from CS2HX: ref/out cannot reference fields, only local variables Now this makes me wonder - are…
Roland Pihlakas
  • 4,246
  • 2
  • 43
  • 64
0
votes
1 answer

InterlockedOr8 on gcc MinGW

I had no problems with the shipped version of MinGW that comes with CodeBlocks 12.11. But now I tried to compile SyncSys. Compiling enet was no problem but compiling SyncSys itself with gcc/MinGW brings the errors, that I can't use the function…
Joshua Behrens
  • 818
  • 13
  • 23
0
votes
1 answer

Architecture-generic InterlockedIncrement for 32/64-bit

What is the best way to use the C++ InterlockedIncrement functionality generic to both 32-bit and 64-bit architectures? (There are separated functions) Is there a better way than using the #if _W64 preprocessor command?
Reflection
  • 1,936
  • 3
  • 21
  • 39
0
votes
4 answers

Lockless Deque in Win32 C++

I'm pretty new to lockless data structures, so for an exercise I wrote (What I hope functions as) a bounded lockless deque (No resizing yet, just want to get the base cases working). I'd just like to have some confirmation from people who know what…
Reggie
  • 73
  • 1
  • 5
0
votes
3 answers

Threading and un-safe variables

I have code listed here: Threading and Sockets. The answer to that question was to modify isListening with volatile. As I remarked, that modifier allowed me to access the variable from another thread. After reading MSDN, I realized that I was…
IAbstract
  • 19,551
  • 15
  • 98
  • 146
0
votes
1 answer

C++ short enum problems with InterlockedCompareExchange16 (with VS2012)

Having referenced this question: Can an enum class be converted to the underlying type?. In my code I have effectively: enum class STATE : short { EMPTY, PRESENT, PARTIAL, }; volatile STATE state; Then I write a typedef and a…
Coder_Dan
  • 1,815
  • 3
  • 23
  • 31
1 2 3
15
16