File tree Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -2208,22 +2208,26 @@ module Array =
22082208 [<CompiledName( " TryPick" ) >]
22092209 let tryPick chooser ( array : _ array ) =
22102210 checkNonNull " array" array
2211- let allChosen = System.Collections.Concurrent.ConcurrentDictionary()
22122211
2213- let pResult =
2212+ let syncRoot = obj()
2213+ let mutable lo = Int32.MaxValue
2214+ let mutable chosen = None
2215+
2216+ let _pResult =
22142217 Parallel.For(
22152218 0 ,
22162219 array.Length,
22172220 ( fun i pState ->
22182221 match chooser array[ i] with
22192222 | None -> ()
22202223 | chosenElement ->
2221- allChosen[ i] <- chosenElement
2222- pState.Break())
2223- )
2224+ lock syncRoot ( fun () ->
2225+ if i < lo then
2226+ lo <- i
2227+ chosen <- chosenElement)
2228+ pState.Break()))
22242229
2225- if pResult.LowestBreakIteration.HasValue then allChosen[ int ( pResult.LowestBreakIteration.GetValueOrDefault())]
2226- else None
2230+ chosen
22272231
22282232 [<CompiledName( " Choose" ) >]
22292233 let choose chooser ( array : 'T array ) =
You can’t perform that action at this time.
0 commit comments