Skip to content

Concurrency/multi-threading safe pre-allocated mutable buffers (e.g. arrays, etc.)

License

Notifications You must be signed in to change notification settings

halleysfifthinc/SafeBuffers.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SafeBuffers

Build Status Coverage Maintenance

Concurrency/multi-threading safe pre-allocated mutable buffers (e.g. arrays, etc.). This package is not registered and should not be assumed to be actively maintained.

Using a simple Vector of e.g. preallocated arrays may not have a strong enough "ownership" guarantee when Tasks yield before finishing using a particular prealloc'ed array. A BufferPool assumes ownership while a particular buffer is in use, preventing use by other Tasks. withbuffer will wait for a buffer to become available when/as needed.

Examples

julia> b1 = BufferPool(2, () -> Ref{Int}())
BufferPool{Base.RefValue{Int64}}(🔒: 0 of 2, size = ())

julia> b2 = BufferPool(2, () -> Vector{Int}(undef, 2))
BufferPool{Vector{Int64}}(🔒: 0 of 2, size = (2,))

julia> b3 = BufferPool(Threads.nthreads(), () -> Vector{Int}(undef, 2))
BufferPool{Vector{Int64}}(🔒: 0 of 8, size = (2,))

julia> withbuffer(b2) do buf
           buf .= 1:2
           sum(abs2, buf)
       end
5

About

Concurrency/multi-threading safe pre-allocated mutable buffers (e.g. arrays, etc.)

Topics

Resources

License

Stars

Watchers

Forks

Languages