From ed5118bc1ddad698ec51d409572c71a244373c31 Mon Sep 17 00:00:00 2001 From: "Andres G. Aragoneses" Date: Fri, 16 Feb 2024 15:07:31 +0800 Subject: [PATCH 1/2] Fsdk: fix build Somehow, the 'macOS--dotnet6-and-mono' and 'linux-*-github--dotnet-*' CI lanes started failing with this compiler error: ``` /home/runner/work/fsx/fsx/Fsdk/Process.fs(22,31): error FS0041: No overloads match for method 'Read'. Known type of argument: int ref Available overloads: - Volatile.Read(location: inref) : bool // Argument 'location' doesn't match - Volatile.Read(location: inref) : byte // Argument 'location' doesn't match - Volatile.Read(location: inref) : float32 // Argument 'location' doesn't match - Volatile.Read(location: inref) : float // Argument 'location' doesn't match - Volatile.Read(location: inref) : int16 // Argument 'location' doesn't match - Volatile.Read(location: inref) : int64 // Argument 'location' doesn't match - Volatile.Read(location: inref) : int // Argument 'location' doesn't match - Volatile.Read(location: inref) : nativeint // Argument 'location' doesn't match - Volatile.Read(location: inref) : sbyte // Argument 'location' doesn't match - Volatile.Read(location: inref) : uint16 // Argument 'location' doesn't match - Volatile.Read(location: inref) : uint32 // Argument 'location' doesn't match - Volatile.Read(location: inref) : uint64 // Argument 'location' doesn't match - Volatile.Read(location: inref) : unativeint // Argument 'location' doesn't match - Volatile.Read<'T when 'T: not struct>(location: inref<'T>) : 'T // Argument 'location' doesn't match ``` Which makes me think that they are upgrading to newer .NET versions instead of being pinned... The build fix works but not sure it's correct at runtime TBH. We will see when we start using the new version of Fsdk nuget package soon... --- Fsdk/Process.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Fsdk/Process.fs b/Fsdk/Process.fs index 58123cb..2f07074 100644 --- a/Fsdk/Process.fs +++ b/Fsdk/Process.fs @@ -19,7 +19,7 @@ module Process = let myTicket = Interlocked.Increment ticketsCount Monitor.Enter innerLock - while myTicket <> Volatile.Read ticketToRide do + while myTicket <> ticketToRide.Value do Monitor.Wait innerLock |> ignore member __.Exit() = From f3b6785a373f8224c0c0e9b5647fbdd08fbcde32 Mon Sep 17 00:00:00 2001 From: "Andres G. Aragoneses" Date: Mon, 19 Feb 2024 19:27:15 +0800 Subject: [PATCH 2/2] Fsdk/Process: fix QueuedLock thread safety According to @vlza (nickname in F#'s discord) this should work (see previous commit to see the build fix, but non-thread-safe approach). --- Fsdk/Process.fs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Fsdk/Process.fs b/Fsdk/Process.fs index 2f07074..ed350c0 100644 --- a/Fsdk/Process.fs +++ b/Fsdk/Process.fs @@ -12,18 +12,18 @@ module Process = // https://stackoverflow.com/a/961904/544947 type internal QueuedLock() = let innerLock = Object() - let ticketsCount = ref 0 - let ticketToRide = ref 1 + let mutable ticketsCount = 0 + let mutable ticketToRide = 1 member __.Enter() = - let myTicket = Interlocked.Increment ticketsCount + let myTicket = Interlocked.Increment &ticketsCount Monitor.Enter innerLock - while myTicket <> ticketToRide.Value do + while myTicket <> Volatile.Read &ticketToRide do Monitor.Wait innerLock |> ignore member __.Exit() = - Interlocked.Increment ticketToRide |> ignore + Interlocked.Increment &ticketToRide |> ignore Monitor.PulseAll innerLock Monitor.Exit innerLock