Reader and writer in multithread in C++
<p>Here is my questions. I have two threads writer1 and writer2 who modify the attributs of a struture, the writer1 writes in attribut1, the writer2 writes in attribut2. And I have a thread Reader who reads the structure. What I'm waiting for is:  When writer1 is writing, writer2 can also write at the same time.(It dosen't cause problem because they modify the different attributs). Of course, when writer2 is writing, writer1 can also write at the same time. But when the Reader is reading the values of the structure, neither writer1 nor writer2 can be writing at the same time.I shoule be sure that the value I'm reading is not changing by other threads</p>

<p>Exemple:</p>

<pre><code>typedef struct
{
    int a;
    double b;

} data;

data glob;

int main()
{

    thread reader([]()
    {
        while(1)
        {
            sleep(1s);
            cout &lt;&lt; glob;
        }
    });

    thread writer1([]()
    { 
        while(1)
            glob.a++;
    });
    thread writer2([]()
    { 
        while(1)
            glob.b++;
    });

    int i;
    cin &gt;&gt;i;
}
</code></pre>