orleans icon indicating copy to clipboard operation
orleans copied to clipboard

Change visibility of AsyncLock to public

Open bwanner opened this issue 10 years ago • 3 comments

Within Orleans there is an internal class AsyncLock that allows to create a mutex that can await async operations.

I discussed making AsyncLock public with @sergeybykov who brought up that Orleans in general is not intended to be a general purpose library. I opened this issue to gauge if there is valid common interest in having AsyncLock available for Orleans applications.

AsyncLock can be useful when dealing with reentrancy to create non-interleaving methods: Say you have a reentrant grain A where A.MyMethod() is supposed to be executed without interleaving. When MyMethod() is making another grain call AsyncLock can be used to await this call while still keeping a section of the code locked.

Feel free to bring up any other uses of this feature or say why you would/wouldn't like it to be public.

bwanner avatar May 28 '16 07:05 bwanner

If what we want is for 2 request for the same grain to not interleave, in theory you could write up something that doesn't rely on a Semaphore(Slim) at all, since grain execution is single threaded (for example by using a TaskCompletionSource if there is contention).

If the intention is to use the lock across several grain activations in a Silo, then that's another story, although not generally recommended, and should be used with caution for cases when it is practical.

jdom avatar May 31 '16 17:05 jdom

I would also discourage usage of AsyncLock since it relies on SemaphoreSlim. Instead, I would use Tasks and TaskCompletionSource, like @jdom suggested.

gabikliot avatar Jun 02 '16 05:06 gabikliot

Implementing a custom lock using TaskCompletionSource seems to be the way to go here, did not think of that :). Maybe that feature can be added to a custom library in OrleansContrib.

bwanner avatar Jun 02 '16 08:06 bwanner