C++ (atomic bool w/ yield)
\nclass FooBar {\nprivate:\n    atomic<bool> alt;\n    int n;\n\npublic:\n    FooBar(int n) {\n        this->n = n;\n        alt = true;\n    }\n\n    void foo(
```\nclass FooBar {\nprivate:\n    atomic<bool> alt;\n    int n;\n\npublic:\n    FooBar(int n) {\n        this->n = n;\n        alt = true;\n    }\n\n    void foo(function<void()> printFoo) {\n        for (int i = 0; i < n; i++) {\n            while (!alt) this_thread::yield();\n            printFoo();\n            alt = false;\n        }\n    }\n\n    void bar(function<void()> printBar) {\n        for (int i = 0; i < n; i++) {\n            while (alt) this_thread::yield();\n            printBar();\n            alt = true;\n        }\n    }\n};\n```
['C']