justinstenning / SharedMemory

C# shared memory classes for sharing data between processes (Array, Buffer and Circular Buffer)
https://www.nuget.org/packages/SharedMemory
Other
566 stars 118 forks source link

Prevent accidental deadlocks in BufferWithLocks (BufferReadWrite, SharedArray) #21

Closed justinstenning closed 7 years ago

justinstenning commented 7 years ago

If a class inherting from BufferWithLocks does not correctly release Read/Write locks, or does not correctly check that the AcquireReadLock/AcquireWriteLock has returned true, it is possible to end up with a deadlock situation where a subsequent Read/Write call will wait indefinitely.

As a safety measure, a ReadWriteTimeout property (defaulting to 100ms) will be added to BufferWithLocks, and all Read/Write operations will timeout with a TimedoutException if the WaitEvent is not set within that timeframe.

If using AcquireReadLock/ReleaseReadLock and AcquireWriteLock/ReleaseWriteLock correctly this timeout will never occur.