parallele-programmierung/u06-1/README.md

21 lines
926 B
Markdown

# Problem 6.1: Barrier without semaphore
Implement a class `Barrier` that realizes a barrier similar to the **`CyclicBarrier`** mentioned on
slide 4-50 (your barrier does not have to be reusable); barriers are also described in the book by
Gleim/Schüle in section 3.2.7 (in German). Don't use semaphores, but only `synchronized`, `wait()`
and `notify/All()`. Your class should look about as follows:
```java
class Barrier {
// …
public Barrier(int nThreads){ }
// nThreads: Number of threads using this barrier
public int await() throws InterruptedException { }
// Cross the barrier, possibly waiting before doing this
// Return value: Position of this thread when arriving at the barrier
}
```
Test your barrier with class `BarrierTest` in the source code folder on th server. In the program's
output, all `a()` invocations must appear before all `b()` invocations `Barrier` if your barrier is
correct.