Skip to content
Discussion options

You must be logged in to vote

Making ReaderWriterLockSlim usable in asynchronous context is not possible. Even if you ignore the fact that its API surface is inherently thread-affine, there is still the issue that its locking semantics are defined to be thread-affine and changing that would be breaking.

This is true for most synchronization primitives in System.Threading; SemaphoreSlim is an exception. Unlike the others, its documentation explicitly states:

The SemaphoreSlim class doesn't enforce thread or task identity on calls to the Wait, WaitAsync, and Release methods.

When you're porting a synchronous code base to async/await, you have to very carefully audit any use of synchronization primitives.

Making these …

Replies: 6 comments 11 replies

Comment options

You must be logged in to vote
3 replies
@lbgitjp
Comment options

@Xyncgas
Comment options

@lbgitjp
Comment options

Comment options

You must be logged in to vote
1 reply
@lbgitjp
Comment options

Answer selected by lbgitjp
Comment options

You must be logged in to vote
3 replies
@Clockwork-Muse
Comment options

@lbgitjp
Comment options

@Clockwork-Muse
Comment options

Comment options

You must be logged in to vote
3 replies
@lbgitjp
Comment options

@TonyValenti
Comment options

@Xyncgas
Comment options

Comment options

You must be logged in to vote
1 reply
@Xyncgas
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
6 participants