Async Lock #2611
Replies: 6 comments
-
Normally locks are supposed to be held for short periods of time, otherwise you lose scalability. It's not clear from your example why would you need this kind of "async" lock, normally the await would be outside of the lock, unless you really have this rather strange requirement that the queue cannot be accessed until an item already dequeued hasn't finished processing. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Stephen Toub proposed that solution and of course there is Stephen Cleary's Nito.AsyncEx. Also I think such a basic coordinating primitive should be part of netstandard, there is definitely no need for language support. |
Beta Was this translation helpful? Give feedback.
-
Yes, but that functionality is already possible today. There are existing CoreFx constructs for this. The language doesn't need to take in any language features here because using these constructs is already easy to do. |
Beta Was this translation helpful? Give feedback.
-
If I could, I would remove the existing lock statement, because those locks are not clearly defined (too magic) and have the error-prone behavior of allowing reentrancy on the same thread. Which would be bad for async when you are re-using threads. |
Beta Was this translation helpful? Give feedback.
-
async lock is reasonably safe, because a reentrent thread would just hit the same lock and also go await (and become available to complete the continuation of the thread that holds the lock). The lack of visibility over the number of (thread-ish async execution paths-- what do we call these?) concurrently async-lock awaiting could be an issue, but that's the same for all aysnc, not just locks. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently we cannot write
lock
withawait
.How about,
This will require
AsyncSemaphore
or similar implementation to haveLockAsync
methods to support asynchronous logic.Implementation,
Beta Was this translation helpful? Give feedback.
All reactions