Repair thread-unsafe modifications of n_alive in F.pass.cpp
In this example, the ctor of G runs in the main thread in the expression G(), and also in the copy ctor of G() in the DECAY_COPY inside std::thread. The main thread destroys the G() instance at the semicolon, and the started thread destroys the G() after it returns. Thus there is a race between the threads on the n_alive variable. The fix is to join with the background thread before attempting to destroy the G in the main thread. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@344820 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -157,8 +157,11 @@ int main()
|
|||||||
{
|
{
|
||||||
assert(G::n_alive == 0);
|
assert(G::n_alive == 0);
|
||||||
assert(!G::op_run);
|
assert(!G::op_run);
|
||||||
std::thread t((G()));
|
{
|
||||||
|
G g;
|
||||||
|
std::thread t(g);
|
||||||
t.join();
|
t.join();
|
||||||
|
}
|
||||||
assert(G::n_alive == 0);
|
assert(G::n_alive == 0);
|
||||||
assert(G::op_run);
|
assert(G::op_run);
|
||||||
}
|
}
|
||||||
@@ -185,8 +188,11 @@ int main()
|
|||||||
{
|
{
|
||||||
assert(G::n_alive == 0);
|
assert(G::n_alive == 0);
|
||||||
assert(!G::op_run);
|
assert(!G::op_run);
|
||||||
std::thread t(G(), 5, 5.5);
|
{
|
||||||
|
G g;
|
||||||
|
std::thread t(g, 5, 5.5);
|
||||||
t.join();
|
t.join();
|
||||||
|
}
|
||||||
assert(G::n_alive == 0);
|
assert(G::n_alive == 0);
|
||||||
assert(G::op_run);
|
assert(G::op_run);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user