1

.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

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.