Skip to content

Commit

Permalink
Merge pull request #1 from NHDaly/reboot
Browse files Browse the repository at this point in the history
Reboot: Update Select.jl for multithreaded, modern Julia
  • Loading branch information
NHDaly authored Sep 4, 2019
2 parents 3afc5c1 + 0a167bf commit 7fcd217
Show file tree
Hide file tree
Showing 8 changed files with 361 additions and 119 deletions.
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ os:
- linux
- osx
julia:
- release
- 1.3
- nightly
env:
- JULIA_NUM_THREADS=1
- JULIA_NUM_THREADS=6


notifications:
email: false
# uncomment the following lines to override the default test script
Expand Down
17 changes: 17 additions & 0 deletions Project.toml
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"]
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
# Select

This is copy of [Jon Malmaud's](https://github.com/malmaud) go inspired select macro for the Julia programming language. I have made a slight syntax modification, but essentially all the code is his.

This packege is currently not registered and can be installed with:
This repo is branched from https://github.com/durcan/Select.jl, which was originally a copy of [Jon Malmaud's](https://github.com/malmaud) go-inspired select macro for the Julia programming language. I have updated the repo for Julia 1.3+, multithreaded the Select macro, and hardened the code a bit.

Install this package via:
```julia
julia> Pkg.add("https://github.com/NHDaly/Select.jl")
```
Pkg.clone("https://github.com/durcan/Select.jl.git")
```

The original README from [durcan/Select.jl](https://github.com/durcan/Select.jl) follows:

-----------------------------------------------------

This is copy of [Jon Malmaud's](https://github.com/malmaud) go inspired select macro for the Julia programming language. I have made a slight syntax modification, but essentially all the code is his.


A select expression is for waiting on multiple communication operations and is of the form:
Expand Down
35 changes: 35 additions & 0 deletions examples/default.jl
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
38 changes: 38 additions & 0 deletions examples/fibonacci.jl
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
Loading

0 comments on commit 7fcd217

Please sign in to comment.