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

Do I have to mallocate SLIST_HEADER?

The guide "Using Singly Linked Lists" uses _aligned_malloc to allocate the SLIST_HEADER structure before calling InitializeSListHead() on it. Is it a requirement that the list header structure is placed on the heap? I mean, it's declared with…
Seva Alekseyev
  • 59,826
  • 25
  • 160
  • 281
1
vote
2 answers

Parallel.For() with Interlocked.CompareExchange(): poorer performance and slightly different results to serial version

I experimented with calculating the mean of a list using Parallel.For(). I decided against it as it is about four times slower than a simple serial version. Yet I am intrigued by the fact that it does not yield exactly the same result as the serial…
tethered.sun
  • 149
  • 3
  • 14
1
vote
1 answer

How to detect overflow (or underflow) in Interlocked.Add

I want to use an Interlocked.Add method because it's faster for int and long. I have following code for others types: short x = Sum(source, range.Item1, range.Item2); checked { lock (syncRoot) result += x; …
Alex Zhukovskiy
  • 9,565
  • 11
  • 75
  • 151
1
vote
1 answer

Take all items from ConcurrentBag using a swap

I'm trying to take all items in one fell swoop from a ConcurrentBag. Since there's nothing like TryEmpty on the collection, I've resorted to using Interlocked.Exchange in the same fashion as described here: How to remove all Items from…
Brandon
  • 4,491
  • 6
  • 38
  • 59
1
vote
2 answers

Interlocked functions - cannot convert arguments

I need to compile cppunit on ARM platform. All compiles and works fine on release mode, but on debug mode I get following errors: Error 1 error C2664: 'unsigned int CppUnit::_InterlockedIncrement(volatile unsigned int *)' : cannot convert…
Michal
  • 11
  • 1
1
vote
3 answers

locking mechanism that provides information about the state in .NET 3.5

I'm trying to find a way to provide exclusive access to a resource, while at the same time providing information about the state of the lock (_isWorking) for other classes to read. Here's what I have come up with so far : private int _isWorking…
lau
  • 372
  • 4
  • 8
1
vote
2 answers

Lockfree Read value after Interlocked.Exchange?

Lets say we have a class like so: public class Foo { private Bar bar = new Bar(); public void DoStuffInThread1() { var old = Interlocked.Exchange(ref bar,new Bar()); //do things with old //everything is fine…
Roger Johansson
  • 22,764
  • 18
  • 97
  • 193
1
vote
1 answer

Should I use Interlocked.Exchange here or is a standard write sufficient?

The following method attempts to obtain a lock which is shared with some other thread. In the event that the lock can be obtained within a time period, some Action will be executed. If the lock cannot be obtained within the specified time period, I…
JMc
  • 971
  • 2
  • 17
  • 26
1
vote
1 answer

Atomic unlocked access to 64bit blocks of Memory Mapped Files in .NET

We need to share very efficiently block of constantly changing information between two processes. Information fits in 64bits block of memory - so inside one process we'd be able to use Interlocked operations (or probably even just ordinary…
Jan
  • 1,905
  • 17
  • 41
1
vote
1 answer

Does the name "Interlocked" have some particular meaning?

The Interlocked class provides easy access to atomic operations such as fetch and add and compare and swap. MSDN says that this class: Provides atomic operations for variables that are shared by multiple threads. My question is: why is it called…
Gigi
  • 28,163
  • 29
  • 106
  • 188
1
vote
1 answer

InterlockedCompareExchange in windows 98 environment

I am forced to run some applications in windows 98 se. vc6 has strange InterlockedCompareExchange definition: void* InterlockedCompareExchange(void**, void*, void*); msdn defines it like this however (since windows xp): LONG…
Ivars
  • 2,375
  • 7
  • 22
  • 31
1
vote
1 answer

Delphi [volatile] and InterlockedCompareExchange not reliable?

I wrote a simple lock-free node stack (Delp[hi XE4, Win7-64, 32-bit app) where I can have multiple 'stacks' and pop/push nodes between them from various threads simultaneously. It works 99.999% of the time but eventually glitch under a stress test…
AntonE
  • 53
  • 3
1
vote
1 answer

PostgreSQL Lock Row on indefinitely time

I wanna lock one row by some user until he work with this row on indefinitely time and he must unlock it when done. So any others users will not be able to lock this row for yourself. It is possible to do on data base level?
Miles
  • 488
  • 5
  • 19
1
vote
1 answer

Interlocked read on readonly memory page triggers access violation

In order to perform interlocked reads I have used InterlockedCompareExchange function a la value = InterlockedCompareExchange(ptr, 0, 0); Now I stumbled upon unusual situation. I want to use this interlocked "read" on a read-only (write-protected)…
Roland Pihlakas
  • 4,246
  • 2
  • 43
  • 64
1
vote
2 answers

WaitForSingleObject vs Interlocked*

Under WinAPI there is WaitForSingleObject() and ReleaseMutex() function pair. Also there is Interlocked*() function family. I decided to check out performance between capturing single mutex and exchanging interlocked variable. HANDLE…
Ivars
  • 2,375
  • 7
  • 22
  • 31