0 ms 🔥Intuitive | Two Mutex Only | C++ | C 
🚀 Approach

We start with two mutexes (m1 and m2).

m1 is open (unlocked) because foo gets to go first.
m2 is locked because bar needs to wait its turn.



Thre
# 🚀 Approach
1. We start with two mutexes (`m1` and `m2`).
    - `m1` is open (unlocked) because `foo` gets to go first.
    - `m2` is locked because `bar` needs to wait its turn.

2. Thread 1 (`foo`):
    - It grabs `m1`, prints `"foo"`, and then signals (unlocks) `m2` to let `bar` take over.

3. Thread 2 (`bar`):
    - It grabs `m2`, prints `"bar"`, and then signals (unlocks) `m1` so `foo` can go again.

# Code
```cpp []
class FooBar {
private:
    int n;
    mutex m1, m2;

public:
    FooBar(int n) {
        this->n = n;
        m2.lock();
    }

    void foo(function<void()> printFoo) {

        for (int i = 0; i < n; i++) {
            m1.lock();
            // printFoo() outputs "foo". Do not change or remove this line.
            printFoo();
            m2.unlock();
        }
    }

    void bar(function<void()> printBar) {

        for (int i = 0; i < n; i++) {
            m2.lock();
            // printBar() outputs "bar". Do not change or remove this line.
            printBar();
            m1.unlock();
        }
    }
};
```
['C', 'Concurrency', 'C++']