A micro-library that backports/polyfills .NET 9.0+'s System.Threading.Lock to prior framework versions (from .NET Framework 3.5 up to .NET 8.0), providing as much backward compatibility as possible. Optionally works as a source generator.
A micro-library that backports .NET 9.0+'s System.Threading.Lock to prior versions (from .NET Framework 3.5 up to .NET 8.0), providing as much backward compatibility as possible.
Use this library the same way you would use System.Threading.Lock.
In order to get the performance benefits of System.Threading.Lock, you must however multi-target frameworks in your .csproj file.
Example:
<TargetFrameworks>netstandard2.0;net9.0</TargetFrameworks>
This library was benchmarked against locking on an object on .NET 8.0 and no speed or memory allocation difference was noted, whereas when .NET 9.0 was used the performance was ~25% better as opposed to locking on an object.
Check out our list of contributors!