Linked Questions
10 questions linked to/from Does SemaphoreSlim (.NET) prevent same thread from entering block?
16 votes
5 answers
7k views
Locking with nested async calls
I am working on a multi threaded WindowsPhone8 app that has critical sections within async methods. Does anyone know of a way to properly use semaphores / mutexes in C# where you are using nested ...
3 votes
3 answers
1k views
Why does this code not end in a deadlock
I have this C# code: public class Locking { private int Value1; private int Value2; private object lockValue = new Object(); public int GetInt1(int value1, int value2) { ...
4 votes
2 answers
8k views
Does SemaphoreSlim(1, 1) ensures read and writes are flushed from caches like lock?
Extra question Does SemaphoreSlim(1, 1) still ensures that I have the correct output 1000000, even if task1 and task2 run on 2 different cores? Original question Considering the following code snippet,...
2 votes
3 answers
3k views
Resource locking between iterations of the main thread (Async/Await)
Let's say I have a form with two buttons (button1 and button2) and a resource object (r). The resource has its own locking and unlocking code to handle concurrency. The resource could be modified by ...
7 votes
1 answer
2k views
Semaphores for single-threaded asynchronous async-await-style programming
Semaphores are a multi-threading locking mechanism that ensure that only a limited number of threads are running on a given resource. Mutexes are a special case where that limited number is one. ...
0 votes
2 answers
417 views
Method should throw an exception when called by another thread before completion
I have a method StartProcess(). I want this method to throw an exception if the same method is called by another thread at the same time or by the same initial thread before EndProcess() is called. I ...
-2 votes
1 answer
482 views
Locking behaviour when dealing with async/await [closed]
I might be overthinking this, but I'm not sure I understand how locking works when dealing with await/async. Given the following, after each await a different thread can return to execute the next bit ...
-1 votes
1 answer
188 views
Lockless multithreading of an integer
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 ...
2 votes
2 answers
87 views
"Lock Pools" or other solutions for handling memory intensive operations in a .NET Framework backend?
My backend application takes byte arrays that represent image data and applies certain transformations to it, like changing the resolution and such, and then stores this modified data to disk. During ...
0 votes
2 answers
105 views
Why can threads change instance data if it is blocked in another thread?
I began to study lock and immediately a question arose. It docs.microsoft says here: The lock statement acquires the mutual-exclusion lock for a given object, executes a statement block, and then ...