This modules is intended to be used with scripts or quick prototypes.
It makes thread safe all instances of some collections which
also slightly slow down single threaded use. For more robust software,
it is recommended to use threads::concurrent_collections
.
Thread-safe collections:
pthreads :: redef_collections $ Array
Thread-safe refinements of most of the known methods (exceptenlarge
)
pthreads :: redef_collections $ Array
Thread-safe refinements of most of the known methods (exceptenlarge
)
core :: union_find
union–find algorithm using an efficient disjoint-set data structure
# Redef _some_ basic collections to be thread-safe
#
# This modules is intended to be used with scripts or quick prototypes.
# It makes thread safe _all_ instances of _some_ collections which
# also slightly slow down single threaded use. For more robust software,
# it is recommended to use `threads::concurrent_collections`.
#
# Thread-safe collections:
#
# - [x] `Array`
# - [ ] `List`
# - [ ] `HashMap`
# - [ ] `HashSet`
# - [ ] `Ref`
# - [ ] `Queue`
module redef_collections
import pthreads
# Thread-safe refinements of most of the known methods (except `enlarge`)
redef class Array
var mutex = new Mutex
redef fun add(e)
do
mutex.lock
super
mutex.unlock
end
redef fun []=(index, e)
do
mutex.lock
super
mutex.unlock
end
redef fun [](index)
do
mutex.lock
var r = super
mutex.unlock
return r
end
redef fun remove_at(index)
do
mutex.lock
super
mutex.unlock
end
redef fun shift
do
mutex.lock
var r = super
mutex.unlock
return r
end
redef fun unshift(e)
do
mutex.lock
super
mutex.unlock
end
redef fun insert_all(from, pos)
do
mutex.lock
super
mutex.unlock
end
redef fun swap_at(a, b)
do
mutex.lock
super
mutex.unlock
end
redef fun ==(o)
do
mutex.lock
var r = super
mutex.unlock
return r
end
redef fun enlarge(cap)
do
mutex.lock
super
mutex.unlock
end
end
lib/pthreads/redef_collections.nit:17,1--112,3