Skip to content

Commit 772e70c

Browse files
committed
Rename Coroutine to Process
1 parent 37408cc commit 772e70c

10 files changed

Lines changed: 57 additions & 98 deletions

File tree

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ using ResumableFunctions, SimJulia, Distributions, BenchmarkTools
44
while true
55
dt = rand(Exponential(1 / lambd))
66
@yield Timeout(sim, dt)
7-
@coroutine customer(sim, server, mu)
7+
@process customer(sim, server, mu)
88
end
99
end
1010

@@ -18,7 +18,7 @@ end
1818
function test_mm1(n::Float64)
1919
sim = Simulation()
2020
server = Resource(sim)
21-
@coroutine exp_source(sim, 1.0, server, 1.1)
21+
@process exp_source(sim, 1.0, server, 1.1)
2222
run(sim, n)
2323
end
2424

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ end
1111

1212
function run_test()
1313
sim = Simulation()
14-
@coroutine fibonnaci(sim)
14+
@process fibonnaci(sim)
1515
run(sim, 10)
1616
end
1717

examples/Ross_Simulation_7.7_A_repair_problem.ipynb

Lines changed: 20 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
{
3030
"cell_type": "code",
3131
"execution_count": null,
32-
"metadata": {},
32+
"metadata": {
33+
"collapsed": true
34+
},
3335
"outputs": [],
3436
"source": [
3537
"Pkg.update()\n",
@@ -46,7 +48,7 @@
4648
},
4749
{
4850
"cell_type": "code",
49-
"execution_count": 1,
51+
"execution_count": null,
5052
"metadata": {
5153
"collapsed": true
5254
},
@@ -66,8 +68,10 @@
6668
},
6769
{
6870
"cell_type": "code",
69-
"execution_count": 2,
70-
"metadata": {},
71+
"execution_count": null,
72+
"metadata": {
73+
"collapsed": true
74+
},
7175
"outputs": [],
7276
"source": [
7377
"const RUNS = 5\n",
@@ -91,22 +95,11 @@
9195
},
9296
{
9397
"cell_type": "code",
94-
"execution_count": 3,
98+
"execution_count": null,
9599
"metadata": {},
96-
"outputs": [
97-
{
98-
"data": {
99-
"text/plain": [
100-
"machine (generic function with 1 method)"
101-
]
102-
},
103-
"execution_count": 3,
104-
"metadata": {},
105-
"output_type": "execute_result"
106-
}
107-
],
100+
"outputs": [],
108101
"source": [
109-
"@resumable function machine(sim::Simulation, repair_facility::Resource, spares::Store{Coroutine})\n",
102+
"@resumable function machine(sim::Simulation, repair_facility::Resource, spares::Store{Process})\n",
110103
" while true\n",
111104
" try\n",
112105
" @yield Timeout(sim, Inf)\n",
@@ -141,32 +134,21 @@
141134
},
142135
{
143136
"cell_type": "code",
144-
"execution_count": 4,
137+
"execution_count": null,
145138
"metadata": {},
146-
"outputs": [
147-
{
148-
"data": {
149-
"text/plain": [
150-
"start_sim (generic function with 1 method)"
151-
]
152-
},
153-
"execution_count": 4,
154-
"metadata": {},
155-
"output_type": "execute_result"
156-
}
157-
],
139+
"outputs": [],
158140
"source": [
159-
"@resumable function start_sim(sim::Simulation, repair_facility::Resource, spares::Store{Coroutine})\n",
160-
" procs = Coroutine[]\n",
141+
"@resumable function start_sim(sim::Simulation, repair_facility::Resource, spares::Store{Process})\n",
142+
" procs = Process[]\n",
161143
" for i=1:N\n",
162-
" push!(procs, @coroutine machine(sim, repair_facility, spares))\n",
144+
" push!(procs, @process machine(sim, repair_facility, spares))\n",
163145
" end\n",
164146
" @yield Timeout(sim, 0.0)\n",
165147
" for proc in procs\n",
166148
" interrupt(proc)\n",
167149
" end\n",
168150
" for i=1:S\n",
169-
" @yield Put(spares, @coroutine machine(sim, repair_facility, spares))\n",
151+
" @yield Put(spares, @process machine(sim, repair_facility, spares))\n",
170152
" end\n",
171153
"end"
172154
]
@@ -180,7 +162,7 @@
180162
},
181163
{
182164
"cell_type": "code",
183-
"execution_count": 5,
165+
"execution_count": null,
184166
"metadata": {},
185167
"outputs": [
186168
{
@@ -198,8 +180,8 @@
198180
"function sim_repair()\n",
199181
" sim = Simulation()\n",
200182
" repair_facility = Resource(sim)\n",
201-
" spares = Store{Coroutine}(sim)\n",
202-
" @coroutine start_sim(sim, repair_facility, spares)\n",
183+
" spares = Store{Process}(sim)\n",
184+
" @process start_sim(sim, repair_facility, spares)\n",
203185
" msg = run(sim)\n",
204186
" stop_time = now(sim)\n",
205187
" println(\"At time $stop_time: $msg\")\n",
@@ -239,24 +221,6 @@
239221
"end\n",
240222
"println(sum(results)/RUNS)"
241223
]
242-
},
243-
{
244-
"cell_type": "code",
245-
"execution_count": null,
246-
"metadata": {
247-
"collapsed": true
248-
},
249-
"outputs": [],
250-
"source": []
251-
},
252-
{
253-
"cell_type": "code",
254-
"execution_count": null,
255-
"metadata": {
256-
"collapsed": true
257-
},
258-
"outputs": [],
259-
"source": []
260224
}
261225
],
262226
"metadata": {

src/SimJulia.jl

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,22 @@ module SimJulia
1212
import Base.run, Base.now, Base.isless, Base.show, Base.interrupt, Base.yield
1313
import Base.(&), Base.(|)
1414

15-
export AbstractEvent
16-
export value, state, environment
17-
export Event, Timeout
18-
export succeed, fail, @callback, remove_callback
19-
export Operator
20-
export (&), (|)
21-
export Simulation
22-
export run, now, active_process
15+
export AbstractEvent, value, state, environment
16+
export Event, Timeout, succeed, fail, @callback, remove_callback
17+
export Operator, (&), (|)
18+
export Simulation, run, now, active_process
2319
export nowDatetime
24-
export OldProcess, @oldprocess
25-
export yield, interrupt
26-
export Coroutine, @coroutine
27-
export Container, Resource, Store
28-
export Put, Get, Request, Release, cancel, request, @request
20+
export OldProcess, @oldprocess, yield
21+
export Process, @process, interrupt
22+
export Container, Resource, Store, Put, Get, Request, Release, cancel, request, @request
2923

3024
include("base.jl")
3125
include("events.jl")
3226
include("operators.jl")
3327
include("simulations.jl")
3428
include("utils/time.jl")
3529
include("old/processes.jl")
36-
include("coroutines.jl")
30+
include("processes.jl")
3731
include("resources/base.jl")
3832
include("resources/containers.jl")
3933
include("resources/stores.jl")
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
mutable struct Coroutine <: DiscreteProcess
1+
mutable struct Process <: DiscreteProcess
22
bev :: BaseEvent
33
fsm :: ResumableFunctions.FiniteStateMachineIterator
44
target :: AbstractEvent
55
resume :: Function
6-
function Coroutine(func::Function, env::Environment, args::Any...)
6+
function Process(func::Function, env::Environment, args::Any...)
77
cor = new()
88
cor.bev = BaseEvent(env)
99
cor.fsm = func(env, args...)
@@ -13,14 +13,14 @@ mutable struct Coroutine <: DiscreteProcess
1313
end
1414
end
1515

16-
macro coroutine(expr)
16+
macro process(expr)
1717
expr.head != :call && error("Expression is not a function call!")
1818
func = esc(expr.args[1])
1919
args = [esc(expr.args[n]) for n in 2:length(expr.args)]
20-
:(Coroutine($(func), $(args...)))
20+
:(Process($(func), $(args...)))
2121
end
2222

23-
function execute(ev::AbstractEvent, proc::Coroutine)
23+
function execute(ev::AbstractEvent, proc::Process)
2424
try
2525
env = environment(ev)
2626
set_active_process(env, proc)
@@ -37,7 +37,7 @@ function execute(ev::AbstractEvent, proc::Coroutine)
3737
end
3838
end
3939

40-
function interrupt(proc::Coroutine, cause::Any=nothing)
40+
function interrupt(proc::Process, cause::Any=nothing)
4141
if !done(proc.fsm)
4242
remove_callback(proc.resume, proc.target)
4343
proc.target = Timeout(environment(proc); priority=typemax(Int8), value=InterruptException(proc, cause))
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ end
2323
end
2424
end
2525

26-
@resumable function test_interrupter(sim::Simulation, proc::Coroutine)
26+
@resumable function test_interrupter(sim::Simulation, proc::Process)
2727
@yield Timeout(sim, 2)
2828
interrupt(proc)
2929
end
@@ -41,28 +41,28 @@ end
4141
end
4242

4343
sim = Simulation()
44-
@coroutine fibonnaci(sim)
44+
@process fibonnaci(sim)
4545
run(sim, 10)
4646

4747
sim = Simulation()
48-
@coroutine test_process(sim, succeed(Event(sim)))
48+
@process test_process(sim, succeed(Event(sim)))
4949
run(sim)
5050

5151
sim = Simulation()
52-
@coroutine test_process_exception(sim, Timeout(sim, 1, value=TestException()))
52+
@process test_process_exception(sim, Timeout(sim, 1, value=TestException()))
5353
try
5454
run(sim)
5555
catch exc
5656
println("$exc has been thrown")
5757
end
5858

5959
sim = Simulation()
60-
@coroutine test_process_exception(sim, Timeout(sim, value=TestException()))
60+
@process test_process_exception(sim, Timeout(sim, value=TestException()))
6161
run(sim)
6262

6363
sim = Simulation()
64-
proc = @coroutine test_interrupted(sim)
65-
@coroutine test_interrupter(sim, proc)
64+
proc = @process test_interrupted(sim)
65+
@process test_interrupter(sim, proc)
6666
try
6767
run(sim)
6868
catch exc
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ end
1212

1313
@resumable function generate(sim::Simulation, res::Resource)
1414
for i in 1:10
15-
@coroutine client(sim, res, i, 10-i)
15+
@process client(sim, res, i, 10-i)
1616
@yield Timeout(sim, 0.5*rand())
1717
end
1818
end
1919

2020
sim = Simulation()
2121
res = Resource(sim, 2; level=1)
22-
@coroutine generate(sim, res)
22+
@process generate(sim, res)
2323
run(sim)
2424

2525
@resumable function my_consumer(sim::Simulation, con::Container)
@@ -53,8 +53,8 @@ end
5353

5454
sim = Simulation()
5555
con = Container(sim, 10.0; level=5.0)
56-
@coroutine my_consumer(sim, con)
57-
@coroutine my_producer(sim, con)
56+
@process my_consumer(sim, con)
57+
@process my_producer(sim, con)
5858
run(sim)
5959

6060
function source(sim::Simulation, server::Resource)

test/stores.jl renamed to test/resources/stores.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ end
2525

2626
sim = Simulation()
2727
sto = Store{StoreObject}(sim)
28-
@coroutine my_consumer(sim, sto)
29-
@coroutine my_producer(sim, sto)
28+
@process my_consumer(sim, sto)
29+
@process my_producer(sim, sto)
3030
run(sim)

test/runtests.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ for test_file in [
77
"simulations.jl",
88
"utils/time.jl",
99
"old/processes.jl",
10-
"coroutines.jl",
11-
"containers.jl",
12-
"stores.jl",
10+
"processes.jl",
11+
"resources/containers.jl",
12+
"resources/stores.jl",
1313
]
1414
include(testpath(test_file))
1515
end

test/utils/time.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
using SimJulia
2+
using ResumableFunctions
23
using Base.Dates
34

4-
function datetimetest(sim::Simulation)
5+
@resumable function datetimetest(sim::Simulation)
56
println(nowDatetime(sim))
6-
yield(Timeout(sim, Day(2)))
7+
@yield Timeout(sim, Day(2))
78
println(nowDatetime(sim))
89
end
910

1011
datetime = now()
1112
sim = Simulation(datetime)
12-
@oldprocess datetimetest(sim)
13+
@process datetimetest(sim)
1314
run(sim, datetime+Month(3))
1415
println(nowDatetime(sim))

0 commit comments

Comments
 (0)