.NET 9 introduced a new Lock object (System.Threading.Lock). The C# 13 compiler has also been made able to recognize when the lock keyword is used with such a class instance, producing the correct code.
What about the F# lock function? Does it also automatically recognise the new System.Threading.Lock?
Currently I am using is with a function
let lock9 (lock: System.Threading.Lock) (f: unit -> 't) =
let scope = lock.EnterScope()
try f()
finally scope.Dispose()
F# use or using cannot be currently used as scope does not implement IDisposable
.NET 9 introduced a new Lock object (System.Threading.Lock). The C# 13 compiler has also been made able to recognize when the lock keyword is used with such a class instance, producing the correct code.
What about the F# lock function? Does it also automatically recognise the new System.Threading.Lock?
Currently I am using is with a function
let lock9 (lock: System.Threading.Lock) (f: unit -> 't) =
let scope = lock.EnterScope()
try f()
finally scope.Dispose()
F# use or using cannot be currently used as scope does not implement IDisposable
There's an open issue in the F# language repository for this, so I think the answer is currently no. There are some suggestions in the comments for how to add support in your own codebase, if you want to.