C# solution using Monitor.Wait() and Monitor.PulseAll()
Intuition\nThread Signalling\n\n# Code\n\nusing System.Threading;\n\npublic class FooBar {\n    private int n;\n\n    private readonly object mutex = new object
# Intuition\nThread Signalling\n\n# Code\n```\nusing System.Threading;\n\npublic class FooBar {\n    private int n;\n\n    private readonly object mutex = new object();\n    private bool foo = false;\n    private bool bar = true;\n\n    public FooBar(int n) {\n        this.n = n;\n    }\n\n    public void Foo(Action printFoo) {\n        \n        for (int i = 0; i < n; i++) {\n            lock (mutex)\n            {\n                while (bar is false) Monitor.Wait(mutex);\n                bar = false;\n                // printFoo() outputs "foo". Do not change or remove this line.\n                printFoo();\n                foo = true;\n                Monitor.PulseAll(mutex);\n            }\n        }\n    }\n\n    public void Bar(Action printBar) {\n        \n        for (int i = 0; i < n; i++) {\n            lock (mutex)\n            {\n                while (foo is false) Monitor.Wait(mutex);\n                foo = false;\n                // printBar() outputs "bar". Do not change or remove this line.\n                printBar();\n                bar = true;\n                Monitor.PulseAll(mutex);\n            }\n        }\n    }\n}\n```
['C#']