C# Semaphore-based solution
\nusing System.Threading;\n\npublic class Foo {\n    private readonly Semaphore first = new Semaphore(1, 1);\n    private readonly Semaphore second = new Semaph
```\nusing System.Threading;\n\npublic class Foo {\n    private readonly Semaphore first = new Semaphore(1, 1);\n    private readonly Semaphore second = new Semaphore(0, 1);\n    private readonly Semaphore third = new Semaphore(0, 1);\n\n    public void First(Action printFirst) {\n        first.WaitOne();\n        printFirst();\n        second.Release();\n    }\n\n    public void Second(Action printSecond) {\n        second.WaitOne();\n        printSecond();\n        third.Release();\n    }\n\n    public void Third(Action printThird) {\n        third.WaitOne();\n        printThird();\n        first.Release();\n    }\n}\n```
[]