Skip to content

Commit

Permalink
Fsdk/Process: fix QueuedLock thread safety
Browse files Browse the repository at this point in the history
According to @vlza (nickname in F#'s discord) this should work
(see previous commit to see the build fix, but non-thread-safe
approach).
  • Loading branch information
knocte committed Feb 19, 2024
1 parent ed5118b commit bd23c55
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Fsdk/Process.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ module Process =
let ticketToRide = ref 1

member __.Enter() =
let myTicket = Interlocked.Increment ticketsCount
let myTicket = Interlocked.Increment &ticketsCount

Check failure on line 19 in Fsdk/Process.fs

View workflow job for this annotation

GitHub Actions / macOS--dotnet6-and-mono

No overloads match for method 'Increment'.��Known type of argument: inref<int ref>��Available overloads:� - Interlocked.Increment(location: byref<int64>) : int64 // Argument 'location' doesn't match� - Interlocked.Increment(location: byref<int>) : int // Argument 'location' doesn't match� - Interlocked.Increment(location: byref<uint32>) : uint32 // Argument 'location' doesn't match� - Interlocked.Increment(location: byref<uint64>) : uint64 // Argument 'location' doesn't match

Check failure on line 19 in Fsdk/Process.fs

View workflow job for this annotation

GitHub Actions / macOS--dotnet6-and-mono

No overloads match for method 'Increment'.��Known type of argument: inref<int ref>��Available overloads:� - Interlocked.Increment(location: byref<int64>) : int64 // Argument 'location' doesn't match� - Interlocked.Increment(location: byref<int>) : int // Argument 'location' doesn't match� - Interlocked.Increment(location: byref<uint32>) : uint32 // Argument 'location' doesn't match� - Interlocked.Increment(location: byref<uint64>) : uint64 // Argument 'location' doesn't match

Check failure on line 19 in Fsdk/Process.fs

View workflow job for this annotation

GitHub Actions / macOS--dotnet6-and-mono

No overloads match for method 'Increment'.��Known type of argument: inref<int ref>��Available overloads:� - Interlocked.Increment(location: byref<int64>) : int64 // Argument 'location' doesn't match� - Interlocked.Increment(location: byref<int>) : int // Argument 'location' doesn't match

Check failure on line 19 in Fsdk/Process.fs

View workflow job for this annotation

GitHub Actions / macOS--dotnet6-and-mono

No overloads match for method 'Increment'.��Known type of argument: inref<int ref>��Available overloads:� - Interlocked.Increment(location: byref<int64>) : int64 // Argument 'location' doesn't match� - Interlocked.Increment(location: byref<int>) : int // Argument 'location' doesn't match� - Interlocked.Increment(location: byref<uint32>) : uint32 // Argument 'location' doesn't match� - Interlocked.Increment(location: byref<uint64>) : uint64 // Argument 'location' doesn't match

Check failure on line 19 in Fsdk/Process.fs

View workflow job for this annotation

GitHub Actions / macOS--dotnet6-and-mono

No overloads match for method 'Increment'.��Known type of argument: inref<int ref>��Available overloads:� - Interlocked.Increment(location: byref<int64>) : int64 // Argument 'location' doesn't match� - Interlocked.Increment(location: byref<int>) : int // Argument 'location' doesn't match� - Interlocked.Increment(location: byref<uint32>) : uint32 // Argument 'location' doesn't match� - Interlocked.Increment(location: byref<uint64>) : uint64 // Argument 'location' doesn't match

Check failure on line 19 in Fsdk/Process.fs

View workflow job for this annotation

GitHub Actions / macOS--dotnet6-and-mono

No overloads match for method 'Increment'.��Known type of argument: inref<int ref>��Available overloads:� - Interlocked.Increment(location: byref<int64>) : int64 // Argument 'location' doesn't match� - Interlocked.Increment(location: byref<int>) : int // Argument 'location' doesn't match

Check failure on line 19 in Fsdk/Process.fs

View workflow job for this annotation

GitHub Actions / macOS--dotnet6-and-mono

No overloads match for method 'Increment'.��Known type of argument: inref<int ref>��Available overloads:� - Interlocked.Increment(location: byref<int64>) : int64 // Argument 'location' doesn't match� - Interlocked.Increment(location: byref<int>) : int // Argument 'location' doesn't match� - Interlocked.Increment(location: byref<uint32>) : uint32 // Argument 'location' doesn't match� - Interlocked.Increment(location: byref<uint64>) : uint64 // Argument 'location' doesn't match

Check failure on line 19 in Fsdk/Process.fs

View workflow job for this annotation

GitHub Actions / macOS--dotnet6-and-mono

No overloads match for method 'Increment'.��Known type of argument: inref<int ref>��Available overloads:� - Interlocked.Increment(location: byref<int64>) : int64 // Argument 'location' doesn't match� - Interlocked.Increment(location: byref<int>) : int // Argument 'location' doesn't match� - Interlocked.Increment(location: byref<uint32>) : uint32 // Argument 'location' doesn't match� - Interlocked.Increment(location: byref<uint64>) : uint64 // Argument 'location' doesn't match
Monitor.Enter innerLock

while myTicket <> ticketToRide.Value do
while myTicket <> &ticketToRide.Value do

Check failure on line 22 in Fsdk/Process.fs

View workflow job for this annotation

GitHub Actions / macOS--dotnet6-and-mono

Cannot take the address of the value returned from the expression. Assign the returned value to a let-bound value before taking the address.

Check failure on line 22 in Fsdk/Process.fs

View workflow job for this annotation

GitHub Actions / macOS--dotnet6-and-mono

Cannot take the address of the value returned from the expression. Assign the returned value to a let-bound value before taking the address.

Check failure on line 22 in Fsdk/Process.fs

View workflow job for this annotation

GitHub Actions / macOS--dotnet6-and-mono

Cannot take the address of the value returned from the expression. Assign the returned value to a let-bound value before taking the address.

Check failure on line 22 in Fsdk/Process.fs

View workflow job for this annotation

GitHub Actions / macOS--dotnet6-and-mono

Cannot take the address of the value returned from the expression. Assign the returned value to a let-bound value before taking the address.

Check failure on line 22 in Fsdk/Process.fs

View workflow job for this annotation

GitHub Actions / macOS--dotnet6-and-mono

Cannot take the address of the value returned from the expression. Assign the returned value to a let-bound value before taking the address.

Check failure on line 22 in Fsdk/Process.fs

View workflow job for this annotation

GitHub Actions / macOS--dotnet6-and-mono

Cannot take the address of the value returned from the expression. Assign the returned value to a let-bound value before taking the address.
Monitor.Wait innerLock |> ignore

member __.Exit() =
Interlocked.Increment ticketToRide |> ignore
Interlocked.Increment &ticketToRide |> ignore

Check failure on line 26 in Fsdk/Process.fs

View workflow job for this annotation

GitHub Actions / macOS--dotnet6-and-mono

No overloads match for method 'Increment'.��Known type of argument: inref<int ref>��Available overloads:� - Interlocked.Increment(location: byref<int64>) : int64 // Argument 'location' doesn't match� - Interlocked.Increment(location: byref<int>) : int // Argument 'location' doesn't match� - Interlocked.Increment(location: byref<uint32>) : uint32 // Argument 'location' doesn't match� - Interlocked.Increment(location: byref<uint64>) : uint64 // Argument 'location' doesn't match

Check failure on line 26 in Fsdk/Process.fs

View workflow job for this annotation

GitHub Actions / macOS--dotnet6-and-mono

No overloads match for method 'Increment'.��Known type of argument: inref<int ref>��Available overloads:� - Interlocked.Increment(location: byref<int64>) : int64 // Argument 'location' doesn't match� - Interlocked.Increment(location: byref<int>) : int // Argument 'location' doesn't match� - Interlocked.Increment(location: byref<uint32>) : uint32 // Argument 'location' doesn't match� - Interlocked.Increment(location: byref<uint64>) : uint64 // Argument 'location' doesn't match

Check failure on line 26 in Fsdk/Process.fs

View workflow job for this annotation

GitHub Actions / macOS--dotnet6-and-mono

No overloads match for method 'Increment'.��Known type of argument: inref<int ref>��Available overloads:� - Interlocked.Increment(location: byref<int64>) : int64 // Argument 'location' doesn't match� - Interlocked.Increment(location: byref<int>) : int // Argument 'location' doesn't match

Check failure on line 26 in Fsdk/Process.fs

View workflow job for this annotation

GitHub Actions / macOS--dotnet6-and-mono

No overloads match for method 'Increment'.��Known type of argument: inref<int ref>��Available overloads:� - Interlocked.Increment(location: byref<int64>) : int64 // Argument 'location' doesn't match� - Interlocked.Increment(location: byref<int>) : int // Argument 'location' doesn't match� - Interlocked.Increment(location: byref<uint32>) : uint32 // Argument 'location' doesn't match� - Interlocked.Increment(location: byref<uint64>) : uint64 // Argument 'location' doesn't match

Check failure on line 26 in Fsdk/Process.fs

View workflow job for this annotation

GitHub Actions / macOS--dotnet6-and-mono

No overloads match for method 'Increment'.��Known type of argument: inref<int ref>��Available overloads:� - Interlocked.Increment(location: byref<int64>) : int64 // Argument 'location' doesn't match� - Interlocked.Increment(location: byref<int>) : int // Argument 'location' doesn't match

Check failure on line 26 in Fsdk/Process.fs

View workflow job for this annotation

GitHub Actions / macOS--dotnet6-and-mono

No overloads match for method 'Increment'.��Known type of argument: inref<int ref>��Available overloads:� - Interlocked.Increment(location: byref<int64>) : int64 // Argument 'location' doesn't match� - Interlocked.Increment(location: byref<int>) : int // Argument 'location' doesn't match� - Interlocked.Increment(location: byref<uint32>) : uint32 // Argument 'location' doesn't match� - Interlocked.Increment(location: byref<uint64>) : uint64 // Argument 'location' doesn't match
Monitor.PulseAll innerLock
Monitor.Exit innerLock

Expand Down

0 comments on commit bd23c55

Please sign in to comment.