Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AsyncMutex class #1223

Merged
merged 1 commit into from
Aug 23, 2023
Merged

Add AsyncMutex class #1223

merged 1 commit into from
Aug 23, 2023

Conversation

AArnott
Copy link
Member

@AArnott AArnott commented Aug 10, 2023

This adds a more convenient way to execute async code while holding (or waiting for) a mutex.

Mutexes are traditionally very difficult to asynchronously wait for or do async work while holding because they are thread affinitized. This new class creates a dedicated thread to 'own' the mutex while allowing the AsyncMutex owner to await for the mutex and run async code on any thread while holding it.

@AArnott AArnott added this to the v17.8 milestone Aug 10, 2023
@AArnott
Copy link
Member Author

AArnott commented Aug 10, 2023

The linux failure is when the net472 build of the library is executed on the mono runtime. I've been dropping support for mono lately and maybe it's time to drop it from this library as well. But I'm trying a couple things to see if I can get it to work for the new code first.

@AArnott AArnott force-pushed the asyncMutex branch 3 times, most recently from ce704ab to e4a619c Compare August 14, 2023 23:40
Copy link
Member

@lifengl lifengl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me if this is intended for a narrow usage scenario. It is somewhat different from the Mutex, so I am not sure whether using a generic name like an async version of the original class is a good idea, as it may confuse some users.

src/Microsoft.VisualStudio.Threading/AsyncMutex.cs Outdated Show resolved Hide resolved
src/Microsoft.VisualStudio.Threading/AsyncMutex.cs Outdated Show resolved Hide resolved
src/Microsoft.VisualStudio.Threading/AsyncMutex.cs Outdated Show resolved Hide resolved
src/Microsoft.VisualStudio.Threading/AsyncMutex.cs Outdated Show resolved Hide resolved
@AArnott AArnott enabled auto-merge August 23, 2023 18:39
@AArnott AArnott merged commit 4a97489 into microsoft:main Aug 23, 2023
6 checks passed
@AArnott AArnott deleted the asyncMutex branch August 23, 2023 23:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants