-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from NHDaly/reboot
Reboot: Update Select.jl for multithreaded, modern Julia
- Loading branch information
Showing
8 changed files
with
361 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name = "Select" | ||
uuid = "ac7b3b08-bf78-4e82-aa6e-b038cb67d740" | ||
authors = ["Nathan Daly <[email protected]>", "Brett Cornell <[email protected]>", | ||
"Jon Malmaud <[email protected]>"] | ||
version = "0.1.0" | ||
|
||
[deps] | ||
Nullables = "4d1e1d77-625e-5b40-9113-a560ec7a8ecd" | ||
|
||
[compat] | ||
julia = "1.3" | ||
|
||
[extras] | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
|
||
[targets] | ||
test = ["Test"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module Default | ||
using Select | ||
|
||
doevery(secs) = Channel{Int}() do ch | ||
while true | ||
sleep(secs) | ||
put!(ch, 1) | ||
end | ||
end | ||
doafter(secs) = Channel{Int}() do ch | ||
sleep(secs) | ||
put!(ch, 1) | ||
end | ||
|
||
function main() | ||
tick = doevery(0.1) | ||
boom = doafter(0.5) | ||
while true | ||
@select begin | ||
tick => println("tick.") | ||
boom => begin | ||
println("BOOM!") | ||
return | ||
end | ||
_ => begin | ||
println(" .") | ||
sleep(0.05) | ||
end | ||
end | ||
end | ||
end | ||
|
||
main() | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Translated from the Golang Tour's select intro: https://tour.golang.org/concurrency/5 | ||
module Fibonacci | ||
|
||
using Select | ||
import Base.Threads: @spawn | ||
|
||
function fibonacci(c::Channel{>:Int}, quit::Channel{>:Int}) | ||
x, y = 0, 1 | ||
while true | ||
@select begin | ||
c <| x => begin | ||
x, y = y, x+y | ||
end | ||
quit => begin | ||
println("quit") | ||
return | ||
end | ||
end | ||
end | ||
end | ||
|
||
function main() | ||
@sync begin | ||
c = Channel{Int}() | ||
quit = Channel{Int}() | ||
@spawn begin | ||
for i in 0:9 | ||
println(take!(c)) | ||
end | ||
put!(quit, 0) | ||
end | ||
fibonacci(c, quit) | ||
end | ||
end | ||
|
||
main() | ||
|
||
end |
Oops, something went wrong.