1 # This file is part of NIT (http://www.nitlanguage.org).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Example implemented from "The computer Language Benchmarks Game" - Thread-Ring
16 # http://benchmarksgame.alioth.debian.org/
18 # Complete description of the thread-ring :
19 # http://benchmarksgame.alioth.debian.org/u64q/threadring-description.html#threadring
20 module thread_ring
is example
24 # One Actor, who will receive the token
28 # Identification of `self`
31 # The next Actor to which `self` send the token
32 var next
: ThreadRing is noinit
34 # Receive a token, then send it to `next` unless its value is `0`
35 fun send_token
(message
: Int) do
36 if message
== 0 then print id
37 if message
>= 1 then next
.async
.send_token
(message
- 1)
42 # numbers of actors to create the ring
46 var first
= new ThreadRing(1)
47 var current
= new ThreadRing(2)
49 for i
in [3..nb_actors
] do
50 var t
= new ThreadRing(i
)
55 var n
= if args
.is_empty
then 1000 else args
[0].to_i