Skip to content

Commit f3b6785

Browse files
committed
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).
1 parent ed5118b commit f3b6785

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Fsdk/Process.fs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ module Process =
1212
// https://stackoverflow.com/a/961904/544947
1313
type internal QueuedLock() =
1414
let innerLock = Object()
15-
let ticketsCount = ref 0
16-
let ticketToRide = ref 1
15+
let mutable ticketsCount = 0
16+
let mutable ticketToRide = 1
1717

1818
member __.Enter() =
19-
let myTicket = Interlocked.Increment ticketsCount
19+
let myTicket = Interlocked.Increment &ticketsCount
2020
Monitor.Enter innerLock
2121

22-
while myTicket <> ticketToRide.Value do
22+
while myTicket <> Volatile.Read &ticketToRide do
2323
Monitor.Wait innerLock |> ignore
2424

2525
member __.Exit() =
26-
Interlocked.Increment ticketToRide |> ignore
26+
Interlocked.Increment &ticketToRide |> ignore
2727
Monitor.PulseAll innerLock
2828
Monitor.Exit innerLock
2929

0 commit comments

Comments
 (0)