Use System.Threading.Lock where applicable#288
Conversation
slozier
left a comment
There was a problem hiding this comment.
Works for me.
I was trying to see if there was a "cleaner" pattern, but only think I came up with was putting an alias at the top:
#if !NET9_0_OR_GREATER
using Lock = System.Object;
#endif|
Thanks for the review. I want to do the same in IronPython so let's agree here on the pattern, so it matches across the projects. |
|
Interesting. Not sure how I feel about global usings, they seem a bit too magical. 😄 But I'm willing to give it a try... I can see how having if conditions would become noisy with the amount of locks used in IronPython. Alternate in between solution to make it a little less magical could be do drop the global using on .NET 9+ and require |
Well, I do have an opinion on them and my personal preferences. Generally, I am rather conservative:
In this practical case it means that
I'm not sure I understand how this would work without Anyway, I am going to commit my preferred form now, counting on your willing to give it a try. I'll let you merge the PR is you are OK with it, otherwise looking forward to your opinion. |
|
I guess I didn't explain myself well regarding my alternate solution. I meant only keeping the global using for pre .NET 9: #if !NET9_0_OR_GREATER
global using Lock = System.Object;
#endifso that using |
Performance improvement:
System.Threading.Lockprovides a more efficient locking primitive in .NET 9.0+ than locking on a genericobject.