Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Recipe: Double Barrier #43

eric opened this Issue · 0 comments

1 participant



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

Support for "double barriers" #2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.