https://github.com/juliaactors/guards.jl
Actors guarding access to mutable variables
https://github.com/juliaactors/guards.jl
actor-framework actors concurrency concurrent-programming
Last synced: 4 months ago
JSON representation
Actors guarding access to mutable variables
- Host: GitHub
- URL: https://github.com/juliaactors/guards.jl
- Owner: JuliaActors
- License: mit
- Created: 2020-12-01T06:35:38.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-04-29T17:47:26.000Z (about 4 years ago)
- Last Synced: 2025-01-20T18:43:25.058Z (5 months ago)
- Topics: actor-framework, actors, concurrency, concurrent-programming
- Language: Julia
- Homepage:
- Size: 194 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Guards
Let actors guard your mutable variables!
[](https://JuliaActors.github.io/Guards.jl/stable)
[](https://JuliaActors.github.io/Guards.jl/dev)
[](https://github.com/JuliaActors/Guards.jl/actions)
[](https://codecov.io/gh/JuliaActors/Guards.jl)With `Guards` you can wrap mutable variables into a `:guard` actor. That way they can be safely accessed from parallel threads and distributed worker processes via message passing.
## Example
```julia
julia> using Guardsjulia> gd = guard([1,2,3]) # start a guards actor around an array
Guards.Guard{Array{Int64,1}}(Link{Channel{Any}}(Channel{Any}(sz_max:32,sz_curr:0), 1, :guard))julia> call(gd) # get a deep copy of it
3-element Array{Int64,1}:
1
2
3julia> push!(call(gd), 4) # pushing to it ...
4-element Array{Int64,1}:
1
2
3
4julia> call(gd) # the guarded variable has not changed
3-element Array{Int64,1}:
1
2
3julia> call(gd, push!, 4); # if you call it with push!,
julia> @grd gd # ... it got changed (here using the @grd macro)
4-element Array{Int64,1}:
1
2
3
4julia> @grd pop!(gd) # pop! with the macro
4julia> update!(gd, [5,6,7,8])
4-element Array{Int64,1}:
5
6
7
8julia> @grd gd
4-element Array{Int64,1}:
5
6
7
8
````Guards` is part of [`JuliaActors`](https://github.com/JuliaActors).
## Author(s)
- Paul Bayer
**License:** MIT