Guards.jl

Actors guarding access to mutable variables
Author JuliaActors
Popularity
7 Stars
Updated Last
2 Years Ago
Started In
December 2020

Guards

Let actors guard your mutable variables!

Stable Dev Build Status Coverage

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> using Guards

julia> 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
 3

julia> push!(call(gd), 4)   # pushing to it ...
4-element Array{Int64,1}:
 1
 2
 3
 4

julia> call(gd)             # the guarded variable has not changed
3-element Array{Int64,1}:
 1
 2
 3

julia> 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
 4

julia> @grd pop!(gd)        # pop! with the macro
4

julia> update!(gd, [5,6,7,8])
4-element Array{Int64,1}:
 5
 6
 7
 8

julia> @grd gd
4-element Array{Int64,1}:
 5
 6
 7
 8

Guards is part of JuliaActors.

Author(s)

  • Paul Bayer

License: MIT

Used By Packages

No packages found.