Java: 2 atomic integers
\nimport java.util.concurrent.atomic.AtomicInteger;\n\nclass ZeroEvenOdd {\n    private int n;\n    private AtomicInteger counter;\n    private AtomicInteger ma
```\nimport java.util.concurrent.atomic.AtomicInteger;\n\nclass ZeroEvenOdd {\n    private int n;\n    private AtomicInteger counter;\n    private AtomicInteger machine;\n    \n    public ZeroEvenOdd(int n) {\n        this.n = n;\n        this.counter = new AtomicInteger(0);\n        this.machine = new AtomicInteger(0);\n    }\n\n    public void zero(IntConsumer printNumber) throws InterruptedException {\n        while (counter.get() < n) {\n            while (machine.get() != 0 && machine.get() != 2) {}\n            if (counter.get() < n) printNumber.accept(0);\n            machine.incrementAndGet();\n        }\n    }\n\n    public void even(IntConsumer printNumber) throws InterruptedException {\n        while (counter.get() < n) {\n            while (machine.get() != 3) {}\n            if (counter.get() < n) printNumber.accept(counter.incrementAndGet());\n            machine.set(0);\n        }\n    }\n\n    public void odd(IntConsumer printNumber) throws InterruptedException {\n        while (counter.get() < n) {\n            while (machine.get() != 1) {}\n            if (counter.get() < n) printNumber.accept(counter.incrementAndGet());\n            machine.incrementAndGet();\n        }\n    }\n}\n```
['Java']