Recipe: Double Barrier #43

eric opened this Issue Aug 27, 2012 · 0 comments


None yet
1 participant

eric commented Aug 27, 2012


Double barriers enable clients to synchronize the beginning and the end of a computation. When enough processes have joined the barrier, processes start their computation and leave the barrier once they have finished. This recipe shows how to use a ZooKeeper node as a barrier.

The pseudo code in this recipe represents the barrier node as b. Every client process p registers with the barrier node on entry and unregisters when it is ready to leave. A node registers with the barrier node via the Enter procedure below, it waits until x client process register before proceeding with the computation. (The x here is up to you to determine for your system.)


  1. Create a name n = b+"/"+p
  2. Set watch: exists(b + "/ready", true)
  3. Create child: create( n, EPHEMERAL)
  4. L = getChildren(b, false)
  5. if fewer children in L than x, wait for watch event
  6. else create(b + "/ready", REGULAR)


  1. L = getChildren(b, false)
  2. if no children, exit
  3. if p is only process node in L, delete(n) and exit
  4. if p is the lowest process node in L, wait on highest process node in P
  5. else delete(n) if still exists and wait on lowest process node in L
  6. goto 1

Like #42, it seems like this should go in the same gem as the locker.

@zuazo zuazo referenced this issue in zuazo/zookeeper_bridge-cookbook Nov 27, 2014


Support for "double barriers" #2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment