File tree 1 file changed +11
-7
lines changed
1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -2208,22 +2208,26 @@ module Array =
2208
2208
[<CompiledName( " TryPick" ) >]
2209
2209
let tryPick chooser ( array : _ array ) =
2210
2210
checkNonNull " array" array
2211
- let allChosen = System.Collections.Concurrent.ConcurrentDictionary()
2212
2211
2213
- let pResult =
2212
+ let syncRoot = obj()
2213
+ let mutable lo = Int32.MaxValue
2214
+ let mutable chosen = None
2215
+
2216
+ let _pResult =
2214
2217
Parallel.For(
2215
2218
0 ,
2216
2219
array.Length,
2217
2220
( fun i pState ->
2218
2221
match chooser array[ i] with
2219
2222
| None -> ()
2220
2223
| 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()))
2224
2229
2225
- if pResult.LowestBreakIteration.HasValue then allChosen[ int ( pResult.LowestBreakIteration.GetValueOrDefault())]
2226
- else None
2230
+ chosen
2227
2231
2228
2232
[<CompiledName( " Choose" ) >]
2229
2233
let choose chooser ( array : 'T array ) =
You can’t perform that action at this time.
0 commit comments