Class SyncHash
In: lib/more/facets/synchash.rb
Parent: Hash

SyncHash

A thread-safe hash. We use a sync object instead of a mutex, because it is re-entrant. An exclusive lock is needed when writing, a shared lock IS NEEDED when reading.

Uses the delegator pattern to allow for multiple implementations!

  hash = SyncHash.new
  hash = SyncHash.new(Hash.new)   # Delegates

Design

This class uses the delegator pattern. However we don‘t use Ruby‘s delegation facilities, they are more general and powerful than we need here (and slower). Instead a custom (but simple) solution is used.

Usage

  hash = SyncHash.new
  hash = SyncHash.new(Hash.new)   # Delegates

Methods

new  

Classes and Modules

Module SyncHash::Delegator
Module SyncHash::Inheritor

Attributes

delegate  [RW] 

Public Class methods

[Source]

# File lib/more/facets/synchash.rb, line 67
  def initialize(delegate=nil)
    @delegate = delegate
    @sync = ::Sync.new
    if delegate
      self.extend Delegator
    else
      self.extend Inheritor
    end
  end

[Validate]