Multithread to print odd and even numbers I recently started on C++ multithreading. Here is my code to print odd and even numbers in two different thread. Can somebody please review this code?

#include &lt;iostream&gt;
#include &lt;thread&gt;
#include &lt;mutex&gt;
#include &lt;condition_variable&gt;
using namespace std;

int x = 1;
mutex m;
bool evenready = false;
bool oddready = true;
condition_variable cond;
void printEven()
{
    for (; x &lt; 10;) {
        unique_lock&lt;mutex&gt; mlock(m);
        cond.wait(mlock, [] {
            return evenready;
        });
        oddready = true;
        evenready = false;
        cout &lt;&lt; "Even Print" &lt;&lt; x &lt;&lt; endl;
        x++;
        cond.notify_all();
    }
}

void printOdd()
{
    for (; x &lt; 10;){
        unique_lock&lt;mutex&gt; mlock(m);
    cond.wait(mlock, [] {
        return oddready;
    });
    oddready = false;
    evenready = true;
    cout &lt;&lt; "Odd Print" &lt;&lt; x &lt;&lt; endl;
    x++;
    cond.notify_all();
}
}


int main()
{
    thread t1(printOdd);
    thread t2(printEven);
    t1.join();
    t2.join();
    return 0;
}
Multiple threads are usually used to compute things in parallel.
In this example nothing is computed in parallel:
while one thread is running,
the other is waiting.
With no practical value,
it's not a great demonstration of multithreading.
I suggest to look for more practical targets in the future.

Since evenready and oddready always have opposite values,
one of them would be enough, and less error-prone.

Instead of for (; x &lt; 10;) { it's more natural to use while (x &lt; 10) {.

using namespace std; is considered bad practice.