Is there an implicit memory barrier with a synchronized relation on thread :: join?

I have code at work that runs several threads that perform some operations, and if any of them does not work, they set the shared variable to false.

Then the main thread combines all the worker threads. The simulation of this looks something like this (I commented on a possible fix that I don't know if necessary):

#include <thread>
#include <atomic>
#include <vector>
#include <iostream>
#include <cassert>

using namespace std;

//atomic_bool success = true;
bool success = true;

int main()
{
    vector<thread> v;
    for (int i = 0; i < 10; ++i)
    {
        v.emplace_back([=]
        {
            if (i == 5 || i == 6)
            {
                //success.store(false, memory_order_release);
                success = false;
            }
        });
    }
    for (auto& t : v)
        t.join();

    //assert(success.load(memory_order_acquire) == false);
    assert(success == false);

    cout << "Finished" << endl;
    cin.get();
    return 0;
}

Is it likely that the main thread will consider the success variable true, even if one of the workers set it to false?

, thread:: join() (source), , ?

, ( ), (, , , )?

, ( ), thread:: join?

, ( , makefile ), atleast x86, amd64, itanium, arm7.

.

: , .

+1
1

, join . , . , , . .

join , " ". , .

atomic_bool, UB; . , UB. , .

+1

Source: https://habr.com/ru/post/1687580/


All Articles