module Concurrent::Concern::Observable

The [observer pattern](en.wikipedia.org/wiki/Observer_pattern) is one of the most useful design patterns.

The workflow is very simple:

In a single threaded environment the whole pattern is very easy: the ‘subject` can use a simple data structure to manage all its subscribed `observer`s and every `observer` can react directly to every event without caring about synchronization.

In a multi threaded environment things are more complex. The ‘subject` must synchronize the access to its data structure and to do so currently we’re using two specialized ObserverSet: {Concurrent::Concern::CopyOnWriteObserverSet} and {Concurrent::Concern::CopyOnNotifyObserverSet}.

When implementing and ‘observer` there’s a very important rule to remember: **there are no guarantees about the thread that will execute the callback**

Let’s take this example “‘ class Observer

def initialize
  @count = 0
end

def update
  @count += 1
end

end

obs = Observer.new [obj1, obj2, obj3, obj4].each { |o| o.add_observer(obs) } # execute [obj1, obj2, obj3, obj4] “‘

‘obs` is wrong because the variable `@count` can be accessed by different threads at the same time, so it should be synchronized (using either a Mutex or an AtomicFixum)