org.multiverse.api.clock
Class RelaxedPrimitiveClock

java.lang.Object
  extended by org.multiverse.api.clock.RelaxedPrimitiveClock
All Implemented Interfaces:
PrimitiveClock

public final class RelaxedPrimitiveClock
extends Object
implements PrimitiveClock

The RelaxedPrimitiveClock is less strict about increasing the clock. It finds it OK if someone has increased the clock instead of it insisting that it wants to increase the clock as well. Synchronization (commit locks) should prevent transactions sharing state to execute concurrently, so only independent transaction increase the clock.

The reason why this implementation exists, is that it causes less stress on the memory bus because compare and swaps are done. This clock is based on the optimization TL2 V4 made by David Dice.

The RelaxedPrimitiveClock is a first and simple step forwards to prevent contention on the memory bus. The ideal situation would be if the STM didn't rely on a shared clock, so that independent transactions can scale linearly. The experimental STM implementation for the .NET platform already has realized this, at the cause of having potential zombie threads; threads that have entered an illegal state and possibly could enter some kind of non terminating loop 'before' being aborted because the transaction failed to commit.

Warning

A relaxed clock can not be used as a mechanism to find the total number of committed transactions. Because concurrent executing transaction don't both have to increase the clock; as long as one of them does it suffices as well.

A StrictPrimitiveClock is thread-safe.

Reading the version is very cheap (even though a volatile read needs to be executed).

Author:
Peter Veentjer.

Constructor Summary
RelaxedPrimitiveClock()
          Creates a RelaxedPrimitiveClock with 0 as begin version.
 
Method Summary
 long getVersion()
          Returns the current version of this PrimitiveClock.
 long strictTick()
          Executes a strict clock tick by increasing the version.
 long tick()
          Executes a clock tick by increasing the version.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RelaxedPrimitiveClock

public RelaxedPrimitiveClock()
Creates a RelaxedPrimitiveClock with 0 as begin version.

Method Detail

tick

public long tick()
Description copied from interface: PrimitiveClock
Executes a clock tick by increasing the version. The returned value will always be bigger than the current version. Once the tick method completes, the PrimitiveClock.getVersion() method will always return a time equal or larger than.the last tick.

The returned value could be stale as soon as it is received.

Specified by:
tick in interface PrimitiveClock
Returns:
the time after the tick.
See Also:
PrimitiveClock.strictTick()

strictTick

public long strictTick()
Description copied from interface: PrimitiveClock
Executes a strict clock tick by increasing the version. The big difference between the strictTick() and the PrimitiveClock.tick() is that the former will always increase the version for every calling thread and the is allowed to return the same version for concurrent ticks.

The returned value could be stale as soon as it is received.

Specified by:
strictTick in interface PrimitiveClock
Returns:
the time after the tick.
See Also:
PrimitiveClock.tick()

getVersion

public long getVersion()
Description copied from interface: PrimitiveClock
Returns the current version of this PrimitiveClock.

The returned value could be stale as soon as it is received.

Specified by:
getVersion in interface PrimitiveClock
Returns:
the current version.

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2008-2010 Multiverse. All Rights Reserved.