Barrier Synchronization

Slides:



Advertisements
Similar presentations
Scalable Flat-Combining Based Synchronous Queues Danny Hendler, Itai Incze, Nir Shavit and Moran Tzafrir Presentation by Uri Golani.
Advertisements

1 Synchronization A parallel computer is a collection of processing elements that cooperate and communicate to solve large problems fast. Types of Synchronization.
Synchronization without Contention
Synchronization. How to synchronize processes? – Need to protect access to shared data to avoid problems like race conditions – Typical example: Updating.
1 C OMP 346 – W INTER 2015 Tutorial # 5. Semaphores for Barrier Sync A barrier is a type of synchronization method. A barrier for a group of threads or.
Prof. Amr Goneid, AUC1 Analysis & Design of Algorithms (CSCE 321) Prof. Amr Goneid Department of Computer Science, AUC Part R4. Disjoint Sets.
ECE 454 Computer Systems Programming Parallel Architectures and Performance Implications (II) Ding Yuan ECE Dept., University of Toronto
Process Synchronization. Module 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores.
Mutual Exclusion The Art of Multiprocessor Programming Spring 2007.
Monitors & Blocking Synchronization 1. Producers & Consumers Problem Two threads that communicate through a shared FIFO queue. These two threads can’t.
Barrier Synchronization Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit.
Synchronization without Contention John M. Mellor-Crummey and Michael L. Scott+ ECE 259 / CPS 221 Advanced Computer Architecture II Presenter : Tae Jun.
Spin Locks and Contention Based on slides by by Maurice Herlihy & Nir Shavit Tomer Gurevich.
Barrier Synchronization Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit.
Instructore: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Concurrent and.
Barrier Synchronization Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit.
Threading Part 2 CS221 – 4/22/09. Where We Left Off Simple Threads Program: – Start a worker thread from the Main thread – Worker thread prints messages.
Shared Counters and Parallelism Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit.
5.6.2 Thread Synchronization with Semaphores Semaphores can be used to notify other threads that events have occurred –Producer-consumer relationship Producer.
Scalable Reader Writer Synchronization John M.Mellor-Crummey, Michael L.Scott.
Shared Counters and Parallelism Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Modified by Rajeev Alur for.
Synchronization Todd C. Mowry CS 740 November 1, 2000 Topics Locks Barriers Hardware primitives.
Shared Counters and Parallelism Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit.
Multithreading.
Synchronization (Barriers) Parallel Processing (CS453)
1 CSC 221: Computer Programming I Spring 2010 interaction & design  modular design: roulette game  constants, static fields  % operator, string equals.
Jeremy Denham April 7,  Motivation  Background / Previous work  Experimentation  Results  Questions.
CALTECH cs184c Spring DeHon CS184c: Computer Architecture [Parallel and Multithreaded] Day 10: May 8, 2001 Synchronization.
Java Thread and Memory Model
Monitors and Blocking Synchronization Dalia Cohn Alperovich Based on “The Art of Multiprocessor Programming” by Herlihy & Shavit, chapter 8.
Concurrent Queues Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit.
1 Based on: The art of multiprocessor programming Maurice Herlihy and Nir Shavit, 2008 Appendix A – Software Basics Appendix B – Hardware Basics Introduction.
SYNAR Systems Networking and Architecture Group CMPT 886: The Art of Scalable Synchronization Dr. Alexandra Fedorova School of Computing Science SFU.
Concurrent Stacks Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit.
Computer Science 320 A First Program in Parallel Java.
Counting and Distributed Coordination BASED ON CHAPTER 12 IN «THE ART OF MULTIPROCESSOR PROGRAMMING» LECTURE BY: SAMUEL AMAR.
Shared Counters and Parallelism Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit.
Scalable lock-free Stack Algorithm Wael Yehia York University February 8, 2010.
Spin Locks and Contention Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit.
Spin Locks and Contention Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit.
Queue Locks and Local Spinning Some Slides based on: The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit.
Distributed Algorithms (22903) Lecturer: Danny Hendler Lock-free stack algorithms.
CS61C L20 Thread Level Parallelism II (1) Garcia, Spring 2013 © UCB Senior Lecturer SOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Concurrent Skip Lists.
Lecture 9 : Concurrent Data Structures Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit.
Barrier Synchronization
Review Array Array Elements Accessing array elements
Background on the need for Synchronization
Binary Search one reason that we care about sorting is that it is much faster to search a sorted list compared to sorting an unsorted list the classic.
Distributed Algorithms (22903)
Shared Counters and Parallelism
Ivy Eva Wu.
Distributed Algorithms (22903)
Distributed Algorithms (22903)
Threads and Concurrency in Java: Part 2
Counting, Sorting, and Distributed Coordination
CMSC 341 Lecture 10 B-Trees Based on slides from Dr. Katherine Gibson.
Distributed Algorithms (22903)
Synchronization Lecture 23 – Fall 2017.
Lecture 5: Snooping Protocol Design Issues
Barrier Synchronization
Hold up, wait a minute, let me put some async in it
Basics of Recursion Programming with Recursion
Shared Counters and Parallelism
Pools, Counters, and Parallelism
Shared Counters and Parallelism
Shared Counters and Parallelism
slides created by Ethan Apter and Marty Stepp
EE 155 / COMP 122: Parallel Computing
Nir Shavit Multiprocessor Synchronization Spring 2003
Presentation transcript:

Barrier Synchronization Nir Shavit Multiprocessor Synchronization Spring 2003

Ideal Parallel Computation 1 1 1 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Ideal Parallel Computation 2 2 2 1 1 1 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Real-Life Parallel Computation zzz… 1 1 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Real-Life Parallel Computation 2 zzz… 1 1 Uh, oh 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Barrier Synchronization barrier 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Barrier Synchronization 1 1 1 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Barrier Synchronization Until every thread has left here No thread enters here 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Why Do We Care? Mostly of interest to Elsewhere Scientific & numeric computation Elsewhere Garbage collection Rare in systems programming 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Barriers public class Barrier { int count; int size; public Barrier(int n){ this.size = this.count = n; } public void await() { if (count.FetchDec()==1) { this.count = this.size; } else { while (this.count != 0) {} }}}} 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Number threads participating Barriers public class Barrier { int size; int count; public Barrier(int n){ this.size = this.count = n; } public void await() { if (count.FetchDec()==1) { this.count = this.size; } else { while (this.count != 0) {} }}}} Number threads participating 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Number threads not yet arrived Barriers public class Barrier { int size; int count; public Barrier(int n){ this.size = this.count = n; } public void await() { if (count.FetchDec()==1) { this.count = this.size; } else { while (this.count != 0) {} }}}} Number threads not yet arrived 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Barriers public class Barrier { int size; int count; Initialization public Barrier(int n){ this.size = this.count = n; } public void await() { if (count.FetchDec()==1) { this.count = this.size; } else { while (this.count != 0) {} }}}} Initialization 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Barriers public class Barrier { int size; int count; The method public Barrier(int n){ this.size = this.count = n; } public void await() { if (count.FetchDec()==1) { this.count = this.size; } else { while (this.count != 0) {} }}}} The method 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

If I’m last, reset everything Barriers public class Barrier { int size; int count; public Barrier(int n){ this.size = this.count = n; } public void await() { if (count.FetchDec()==1) { this.count = this.size; } else { while (this.count != 0) {} }}}} If I’m last, reset everything 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Wait for rest to catch up Barriers public class Barrier { int size; int count; public Barrier(int n){ this.size = this.count = n; } public void await() { if (count.FetchDec()==1) { this.count = this.size; } else { while (this.count != 0) {} }}}} Wait for rest to catch up 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

What’s wrong with this protocol? Barriers public class Barrier { int count; int size; public Barrier(int n){ this.size = this.count = n; } public void await() { if (count.FetchDec()==1) { this.count = this.size; } else { while (this.count != 0) {} }}}} What’s wrong with this protocol? 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Reuse Barrier b = new Barrier(n); while ( mumble() ) { work(); b.await() } Do work repeat synchronize 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Waiting for Phase 1 to finish Barriers public class Barrier { int count; int size; public Barrier(int n){ this.size = this.count = n; } public void await() { if (count.FetchDec()==1) { this.count = this.size; } else { while (this.count != 0) {} }}}} Waiting for Phase 1 to finish 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Waiting for Phase 1 to finish Barriers public class Barrier { int count; int size; public Barrier(int n){ this.size = this.count = n; } public void await() { if (count.FetchDec()==1) { this.count = this.size; } else { while (this.count != 0) {} }}}} Phase 1 is so over Waiting for Phase 1 to finish 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Barriers public class Barrier { int count; int size; public Barrier(int n){ this.size = this.count = n; } public void await() { if (count.FetchDec()==1) { this.count = this.size; } else { while (this.count != 0) {} }}}} Prepare for phase 2 ZZZZZ…. 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Waiting for Phase 2 to finish Waiting for Phase 1 to finish Barriers public class Barrier { int count; int size; public Barrier(int n){ this.size = this.count = n; } public void await() { if (count.FetchInc()==1) { this.count = this.size; } else { while (this.count != 0) {} }}}} Waiting for Phase 2 to finish Waiting for Phase 1 to finish 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Basic Problem One thread “wraps around” to start phase 2 While another thread is still waiting for phase 1 One solution: Always use two barriers 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Sense-Reversing Barriers public class Barrier { int count, size; boolean sense = true; public void await(boolean mySense) { if (count.FetchDec()==1) { this.count = this.size; this.sense = mySense } else { while (this.sense != mySense) {} }}}} 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Sense-Reversing Barriers public class Barrier { int count, size; boolean sense = true; public void await(boolean mySense) { if (count.FetchDec()==1) { this.count = this.size; this.sense = mySense } else { while (this.sense != mySense) {} }}}} Completed odd or even-numbered phase? 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Sense-Reversing Barriers public class Barrier { int count, size; boolean sense = true; public void await(boolean mySense) { if (count.FetchDec()==1) { this.count = this.size; this.sense = mySense } else { while (this.sense != mySense) {} }}}} Thread working on odd or even-numbered phase? 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Sense-Reversing Barriers public class Barrier { int count, size; boolean sense = true; public void await(boolean mySense) { if (count.FetchDec()==1) { this.count = this.size; this.sense = mySense } else { while (this.sense != mySense) {} }}}} If I’m last, reverse the sense on the way out 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Sense-Reversing Barriers public class Barrier { int count, size; boolean sense = true; public void await(boolean mySense) { if (count.FetchDec()==1) { this.count = this.size; this.sense = mySense } else { while (this.sense != mySense) {} }}}} Otherwise, wait for sense to flip 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Combining Tree Barriers 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Combining Tree Barriers 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Combining Tree Barrier public class CBarrier { int count, size; CBarrier parent; public void await(boolean mySense) { if (this.count.FetchDec()==1){ if (this.parent != null) this.parent.await(); this.count = this.size; this.sense = mySense } else { while (this.sense != mySense) {} }}}} 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Combining Tree Barrier public class CBarrier { int count, size; CBarrier parent; public void await(boolean mySense) { if (this.count.FetchDec()==1){ if (this.parent != null) this.parent.await(); this.count = this.size; this.sense = mySense } else { while (this.sense != mySense) {} }}}} Parent barrier in tree 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Combining Tree Barrier public class CBarrier { int count, size; CBarrier parent; public void await(boolean mySense) { if (this.count.FetchDec()==1){ if (this.parent != null) this.parent.await(); this.count = this.size; this.sense = mySense } else { while (this.sense != mySense) {} }}}} Thread working on odd or even-numbered phase? 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Combining Tree Barrier public class CBarrier { int count, size; CBarrier parent; public void await(boolean mySense) { if (this.count.FetchDec()==1){ if (this.parent != null) this.parent.await(); this.count = this.size; this.sense = mySense } else { while (this.sense != mySense) {} }}}} Am I last? 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Combining Tree Barrier public class CBarrier { int count, size; CBarrier parent; public void await(boolean mySense){ if (this.count.FetchDec()==1){ if (this.parent != null) this.parent.await(); this.count = this.size; this.sense = mySense } else { while (this.sense != mySense) {} }}}} Wait on parent barrier, if any 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Combining Tree Barrier public class CBarrier { int count, size; CBarrier parent; public void await(boolean mySense){ if (this.count.FetchDec()==1){ if (this.parent != null) this.parent.await(); this.count = this.size; this.sense = mySense } else { while (this.sense != mySense) {} }}}} Prepare for next phase 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Combining Tree Barrier public class CBarrier { int count, size; CBarrier parent; public void await(boolean mySense) { if (this.count.FetchDec()==1){ if (this.parent != null) this.parent.await(); this.count = this.size; this.sense = mySense } else { while (this.sense != mySense) {} }}}} Wake up others at this level 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Combining Tree Barrier public class CBarrier { int count, size; CBarrier parent; public void await(boolean mySense) { if (this.count.FetchDec()==1){ if (this.parent != null) this.parent.await(); this.count = this.size; this.sense = mySense } else { while (this.sense != mySense) {} }}}} I’m not last, wait for release 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Combining Tree Barrier No sequential bottleneck FetchDec calls proceed in parallel Low memory contention Same reason Cache behavior Local spinning on bus-based architecture Not so good for distributed 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Remarks Everyone spins on sense field Sequential bottleneck Local spinning on bus-based (good) Network hot-spot on distributed architecture (bad) Sequential bottleneck Sequence of FetchInc() calls Not really scalable 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Tournament Tree Barrier If tree nodes have fan-in 2 Don’t need to call FetchDec() Winner chosen statically At level i If i-th bit of id is zero, move up Otherwise keep back 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Tournament Tree Barriers winner loser winner loser winner loser 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Tournament Tree Barriers All flags blue 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Tournament Tree Barriers Loser thread sets winner’s flag 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Tournament Tree Barriers Loser spins on own flag 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Tournament Tree Barriers Winner spins on own flag 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Tournament Tree Barriers Winner sees own flag, moves up, spins 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Tournament Tree Barriers Bingo! 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Tournament Tree Barriers Sense-reversing: next time use blue flags 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Tournament Barrier class TBarrier { boolean flag; TBarrier partner; TBarrier parent; boolean top; … } 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Notifications delivered here Tournament Barrier class TBarrier { boolean flag; TBarrier partner; TBarrier parent; boolean top; … } Notifications delivered here 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Other thead at same level Tournament Barrier class TBarrier { boolean flag; TBarrier partner; TBarrier parent; boolean top; … } Other thead at same level 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Parent (winner) or null (loser) Tournament Barrier class TBarrier { boolean flag; TBarrier partner; TBarrier parent; boolean top; … } Parent (winner) or null (loser) 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Tournament Barrier Am I the root? class TBarrier { boolean flag; TBarrier partner; TBarrier parent; boolean top; … } Am I the root? 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Tournament Barrier void await(boolean mySense) { if (this.top) { return; } else if (this.parent != null) { while (this.flag[round] != mySense) {}; this.parent.await(mySense); this.partner.flag[round] = mysense; } else { this.partner.flag[round] = mySense; }}} 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Tournament Barrier The root, c’est moi void await(boolean mySense) { if (this.top) { return; } else if (this.parent != null) { while (this.flag[round] != mySense) {}; this.parent.await(mySense); this.partner.flag[round] = mysense; } else { this.partner.flag[round] = mySense; }}} The root, c’est moi 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Tournament Barrier I am already a winner void await(boolean mySense) { if (this.top) { return; } else if (this.parent != null) { while (this.flag[round] != mySense) {}; this.parent.await(mySense); this.partner.flag[round] = mysense; } else { this.partner.flag[round] = mySense; }}} I am already a winner 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Wait for partner to show up Tournament Barrier void await(boolean mySense) { if (this.top) { return; } else if (this.parent != null) { while (this.flag[round] != mySense) {}; this.parent.await(mySense); this.partner.flag[round] = mysense; } else { this.partner.flag[round] = mySense; }}} Wait for partner to show up 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Tournament Barrier Synchronize upstairs void await(boolean mySense) { if (this.top) { return; } else if (this.parent != null) { while (this.flag[round] != mySense) {}; this.parent.await(mySense); this.partner.flag[round] = mysense; } else { this.partner.flag[round] = mySense; }}} Synchronize upstairs 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Tournament Barrier Notify partner void await(boolean mySense) { if (this.top) { return; } else if (this.parent != null) { while (this.flag[round] != mySense) {}; this.parent.await(mySense); this.partner.flag[round] = mysense; } else { this.partner.flag[round] = mySense; }}} Notify partner 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

My thread is such a loser Tournament Barrier void await(boolean mySense) { if (this.top) { return; } else if (this.parent != null) { while (this.flag[round] != mySense) {}; this.parent.await(mySense); this.partner.flag[round] = mysense; } else { this.partner.flag[round] = mySense; }}} My thread is such a loser 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Tournament Barrier Tell partner I’m here void await(boolean mySense) { if (this.top) { return; } else if (this.parent != null) { while (this.flag[round] != mySense) {}; this.parent.await(mySense); this.partner.flag[round] = mysense; } else { this.partner.flag[round] = mySense; }}} Tell partner I’m here 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Wait for partner to release me Tournament Barrier void await(boolean mySense) { if (this.top) { return; } else if (this.parent != null) { while (this.flag[round] != mySense) {}; this.parent.await(mySense); this.partner.flag[round] = mysense; } else { this.partner.flag[round] = mySense; }}} Wait for partner to release me 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Remarks No need for read-modify-write calls Each thread spins on fixed location Good for bus-based architectures Good for distributed architectures 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Dissemination Barrier At round i Thread A notifies thread A+2i (mod n) Requires log n rounds 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Dissemination Barrier +1 +2 +4 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Dissemination Details Use two copies of fields Avoids interference Use sense-reversing Avoid reinitializing fields Thread Arguments Parity of round Sense (flips when round becomes 0) 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Dissemination Barrier public class DBarrier { private boolean flags[2][logn]; private DBarrier partners[2][logn]; } 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Dissemination Barrier public class DBarrier { private boolean flags[2][logn]; private DBarrier partners[2][logn]; } Use two copies to avoid interference 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Dissemination Barrier public class DBarrier { private boolean flags[2][logn]; private DBarrier partners[2][logn]; } One element per round 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Dissemination Barrier public class DBarrier { private boolean flags[2][logn]; private DBarrier partners[2][logn]; } Notify me here 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Dissemination Barrier public class DBarrier { private boolean flags[2][logn]; private DBarrier partners[2][logn]; } Barrier for thread A + 2i 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Dissemination Barrier void await(int parity, boolean mySense) { for (int i=0; i<logn; i++) { this.partner[parity].flags[i] = mySense; while (this.flags[i] != mySense) {} } 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Dissemination Barrier void await(int parity, boolean mySense) { for (int i=0; i<logn; i++) { this.partner[parity].flags[i] = mySense; while (this.flags[i] != mySense) {} } Parity of current phase 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Dissemination Barrier void await(int parity, boolean mySense) { for (int i=0; i<logn; i++) { this.partner[parity].flags[i] = mySense; while (this.flags[i] != mySense) {} } Flips when parity becomes 0 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Dissemination Barrier void await(int parity, boolean mySense) { for (int i=0; i<logn; i++) { this.partner[parity].flags[i] = mySense; while (this.flags[i] != mySense) {} } Notify thread A+2i 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Dissemination Barrier void await(int parity, boolean mySense) { for (int i=0; i<logn; i++) { this.partner[parity].flags[i] = mySense; while (this.flags[i] != mySense) {} } Wait for thread A-2i 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Remarks Every thread spins in the same place Good for distributed implementations Works even if n not a power of 2 4-Feb-19 M. Herlihy & N. Shavit (c) 2003

Clip Art 4-Feb-19 M. Herlihy & N. Shavit (c) 2003