synchronization - F# lock function with System.Threading.Lock - Stack Overflow

.NET 9 introduced a new Lock object (System.Threading.Lock). The C# 13 compiler has also been made able

.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

Share Improve this question edited Mar 2 at 22:20 Franco Tiveron asked Mar 2 at 22:10 Franco TiveronFranco Tiveron 2,9361 gold badge27 silver badges44 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745116654a4612166.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信