forked from nblockchain/fantomless
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththreadring4.fs
37 lines (34 loc) · 900 Bytes
/
threadring4.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/// The Computer Language Benchmarks Game
///
/// http://shootout.alioth.debian.org/
///
/// contributed by Jomo Fisher
/// modified by Kostas Rontogiannis
///
/// Using an array of Async<unit> for the workers and
/// a shared token between threads.
///
/// Compile :
/// fsc --tailcalls+ -O --platform:x64 ThreadRingNew.fs -o ThreadRingNew.exe
/// Execute :
/// mono ThreadRingNew.exe 50000000
module Threadring
let NumberOfThreads = 503
let mutable (workers : Async<unit> []) = null
let mutable token = -1
let createWorker i =
let next = (i + 1) % NumberOfThreads
async {
if token = 0 then
printfn "%d" (i + 1)
exit 0
else
token <- token - 1
return! workers.[next]
}
[<EntryPoint>]
let main args =
token <- int args.[0]
workers <- Array.init NumberOfThreads createWorker
Async.StartImmediate(workers.[0])
0