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

Improve async lock #1520

Merged
merged 10 commits into from
Sep 25, 2022
Merged

Improve async lock #1520

merged 10 commits into from
Sep 25, 2022

Conversation

chkr1011
Copy link
Collaborator

This pull request adds a new implementation of the Async Lock which has no longer a dead lock issue.

@chkr1011 chkr1011 marked this pull request as draft September 16, 2022 21:36
@chkr1011 chkr1011 changed the title [WIP] Improve async lock Improve async lock Sep 16, 2022
@logicaloud
Copy link
Contributor

Should the _isDisposed check in WaitAsync move inside the _syncRoot lock a bit further down?

@chkr1011
Copy link
Collaborator Author

Should the _isDisposed check in WaitAsync move inside the _syncRoot lock a bit further down?

Why do you think so? The field is atomic to there is no need to lock first in my opinion.

@logicaloud
Copy link
Contributor

I was thinking about multithreaded access where the bool is modified in one thread, then sits in a register and another thread reads a stale value. Maybe the bool could be declared as volatile or moved into the lock (https://learn.microsoft.com/en-us/archive/msdn-magazine/2012/december/csharp-the-csharp-memory-model-in-theory-and-practice#thread-communication-patterns). I'm not sure if it would make much of a difference in practice.

@chkr1011
Copy link
Collaborator Author

Makes sense. I will move it for sure.

@chkr1011 chkr1011 marked this pull request as ready for review September 24, 2022 07:50
@chkr1011 chkr1011 merged commit e050e2d into master Sep 25, 2022
@chkr1011 chkr1011 deleted the Improve-AsyncLock branch September 25, 2022 08:26
sebastian-dev added a commit to sebastian-dev/MQTTnet that referenced this pull request Sep 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants