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 Standard 2.0 up to .NET 8.0), providing as much similar functionality 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.
Check out our list of contributors!