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

Prevent using Monitor with other lock types #231

Open
yaakov-h opened this issue Dec 24, 2024 · 0 comments
Open

Prevent using Monitor with other lock types #231

yaakov-h opened this issue Dec 24, 2024 · 0 comments

Comments

@yaakov-h
Copy link
Member

C# 13 will warn when upcasting System.Threading.Lock to object in order to prevent accidentally using lock(object) rather than lock(Lock), and therefore calling Monitor.Enter/Monitor.Exit over the Lock object.

https://github.com/dotnet/csharplang/blob/d0c84ab39867f28914180ce31099d5aefc3c8280/proposals/csharp-13.0/lock-object.md?plain=1#L72-L90

https://github.com/dotnet/csharplang/blob/main/meetings/2023/LDM-2023-12-04.md?plain=1#L35-L44

We should consider doing the same if other lock types are upcasted, such as SemaphoreSlim.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant