You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+5Lines changed: 5 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,10 @@
1
1
# News
2
2
3
+
## v1.1.0 - 2023-08-02
4
+
5
+
- Start using `Base`'s API: `Base.unlock`, `Base.islocked`, `Base.isready`, `Base.put!`, `Base.take!`. Deprecate `put`, `release`. Moreover, consider using `Base.take!` instead of `Base.get` (which was not deprecated yet, as we decide which semantics to follow). Lastly, `Base.lock` and `Base.trylock` are **not** implement -- they are superficially similar to `request` and `tryrequest`, but have to be explicitly `@yield`-ed.
6
+
- Implement `tryrequest` (similar to `Base.trylock`). However, consider also using `Base.isready` and `request` instead of `tryrequest`.
Copy file name to clipboardExpand all lines: docs/src/examples/Latency.md
+58-37Lines changed: 58 additions & 37 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,28 +7,32 @@ In this example we show how to separate the time delay between processes from th
7
7
### Load Packages
8
8
9
9
10
-
```julia
10
+
```jldoctest 1; output = false
11
11
using ConcurrentSim
12
12
using ResumableFunctions
13
-
import ConcurrentSim.put
14
-
import Base.get
13
+
import Base: put!, take!
14
+
15
+
# output
15
16
```
16
17
17
18
### Define Constants
18
19
19
20
20
-
```julia
21
-
srand(8710) # set random number seed for reproducibility
21
+
```jldoctest 1; output = false
22
22
const SIM_DURATION = 100.
23
23
const SEND_PERIOD = 5.0
24
24
const RECEIVE_PERIOD = 3.0;
25
+
26
+
nothing # hide
27
+
28
+
# output
25
29
```
26
30
27
31
### Define Cable model
28
32
The `Cable` contains reference to the simulation it is part of, the delay that messages experience, and a store that contains the sent messages
29
33
30
34
31
-
```julia
35
+
```jldoctest 1; output = false
32
36
mutable struct Cable
33
37
env::Simulation
34
38
delay::Float64
@@ -38,79 +42,96 @@ mutable struct Cable
38
42
return new(env, delay, Store{String}(env))
39
43
end
40
44
end;
45
+
46
+
nothing # hide
47
+
48
+
# output
41
49
```
42
50
43
51
The latency function is a generator which yields two events: first a `timeout` that represents the transmission delay, then a put event when the message gets stored in the store.
44
52
45
53
46
-
```julia
54
+
```jldoctest 1; output = false
47
55
@resumable function latency(env::Simulation, cable::Cable, value::String)
48
56
@yield timeout(cable.env, cable.delay)
49
-
@yieldput(cable.store, value)
50
-
end;
57
+
@yield put!(cable.store, value)
58
+
end;
59
+
60
+
nothing # hide
61
+
62
+
# output
51
63
```
52
64
53
-
The `put` and `get` functions allow interaction with the cable (note that these are not `@resumable` because they need to return the result of the operation and not the operation itself).
65
+
The `put!` and `take!` functions allow interaction with the cable (note that these are not `@resumable` because they need to return the result of the operation and not the operation itself).
54
66
55
67
56
-
```julia
57
-
functionput(cable::Cable, value::String)
68
+
```jldoctest 1; output = false
69
+
function put!(cable::Cable, value::String)
58
70
@process latency(cable.env, cable, value) # results in the scheduling of all events generated by latency
59
71
end
60
72
61
-
functionget(cable::Cable)
62
-
get(cable.store) # returns an element stored in the cable store
73
+
function take!(cable::Cable); output = false
74
+
take!(cable.store) # returns an element stored in the cable store
63
75
end;
76
+
77
+
nothing # hide
78
+
79
+
# output
64
80
```
65
81
66
82
The `sender` and `receiver` generators yield events to the simulator.
67
83
68
84
69
-
```julia
85
+
```jldoctest 1; output = false
70
86
@resumable function sender(env::Simulation, cable::Cable)
71
87
while true
72
88
@yield timeout(env, SEND_PERIOD)
73
89
value = "sender sent this at $(now(env))"
74
-
put(cable, value)
90
+
put!(cable, value)
75
91
end
76
92
end
77
93
78
94
@resumable function receiver(env::Simulation, cable::Cable)
79
95
while true
80
96
@yield timeout(env, RECEIVE_PERIOD)
81
-
msg =@yieldget(cable)
97
+
msg = @yield take!(cable)
82
98
println("Received this at $(now(env)) while $msg")
83
99
end
84
100
end;
101
+
102
+
nothing # hide
103
+
104
+
# output
85
105
```
86
106
87
107
Create simulation, register events, and run!
88
108
89
109
90
-
```julia
110
+
```jldoctest 1
91
111
env = Simulation()
92
112
cable = Cable(env, 10.)
93
113
@process sender(env, cable)
94
114
@process receiver(env, cable)
95
115
96
116
run(env, SIM_DURATION)
97
-
```
98
-
99
-
Received this at 15.0 while sender sent this at 5.0
100
-
Received this at 20.0 while sender sent this at 10.0
101
-
Received this at 25.0 while sender sent this at 15.0
102
-
Received this at 30.0 while sender sent this at 20.0
103
-
Received this at 35.0 while sender sent this at 25.0
104
-
Received this at 40.0 while sender sent this at 30.0
105
-
Received this at 45.0 while sender sent this at 35.0
106
-
Received this at 50.0 while sender sent this at 40.0
107
-
Received this at 55.0 while sender sent this at 45.0
108
-
Received this at 60.0 while sender sent this at 50.0
109
-
Received this at 65.0 while sender sent this at 55.0
110
-
Received this at 70.0 while sender sent this at 60.0
111
-
Received this at 75.0 while sender sent this at 65.0
112
-
Received this at 80.0 while sender sent this at 70.0
113
-
Received this at 85.0 while sender sent this at 75.0
114
-
Received this at 90.0 while sender sent this at 80.0
115
-
Received this at 95.0 while sender sent this at 85.0
116
117
118
+
# output
119
+
120
+
Received this at 15.0 while sender sent this at 5.0
121
+
Received this at 20.0 while sender sent this at 10.0
122
+
Received this at 25.0 while sender sent this at 15.0
123
+
Received this at 30.0 while sender sent this at 20.0
124
+
Received this at 35.0 while sender sent this at 25.0
125
+
Received this at 40.0 while sender sent this at 30.0
126
+
Received this at 45.0 while sender sent this at 35.0
127
+
Received this at 50.0 while sender sent this at 40.0
128
+
Received this at 55.0 while sender sent this at 45.0
129
+
Received this at 60.0 while sender sent this at 50.0
130
+
Received this at 65.0 while sender sent this at 55.0
131
+
Received this at 70.0 while sender sent this at 60.0
132
+
Received this at 75.0 while sender sent this at 65.0
133
+
Received this at 80.0 while sender sent this at 70.0
134
+
Received this at 85.0 while sender sent this at 75.0
135
+
Received this at 90.0 while sender sent this at 80.0
136
+
Received this at 95.0 while sender sent this at 85.0
0 commit comments