Multi-threading and avoiding deadlocks via Timing

  • Thread starter Thread starter puzzlecracker
  • Start date Start date
P

puzzlecracker

There is a common way to deal with deadlock using timeouts to obtain
multiple locks (In java, there is a tryLock for that). I wonder about
common ways to avoid deadlock prevalent in CSharp. Is there tryLock.
What are the tools .NET provides to deal with them.

I am designing an application where I have a lot of distinct, yet
cooperative, components interacting with each other in a atomic way.
Hence I am looking for patterns and models that specifically
target .NET platform to avoid deadlocks.


Thanks
 
puzzlecracker said:
There is a common way to deal with deadlock using timeouts to obtain
multiple locks (In java, there is a tryLock for that). I wonder about
common ways to avoid deadlock prevalent in CSharp. Is there tryLock.
What are the tools .NET provides to deal with them.

The equivalent should be System.Threading.Monitor class TryEnter method.

The other .NET threading stuff are in the same namespace.
I am designing an application where I have a lot of distinct, yet
cooperative, components interacting with each other in a atomic way.
Hence I am looking for patterns and models that specifically
target .NET platform to avoid deadlocks.

tryLock/TryEnter does not in any ways prevent deadlocks - it is
just a non-blocking attempt to get a lock.

The ways to avoid deadlocks in any context are:
- strict division of responsibilities
- specific lock order

Arne
 
Back
Top