diff options
author | Billy Robert O'Neal III <bion@microsoft.com> | 2018-10-19 23:45:45 +0000 |
---|---|---|
committer | Billy Robert O'Neal III <bion@microsoft.com> | 2018-10-19 23:45:45 +0000 |
commit | e04704b9a97a53733b5c3dc43271476d9670e432 (patch) | |
tree | 8c853d751f31172514c2781e2e2e7137498fc808 /libcxx/test/std/thread/thread.threads/thread.thread.class | |
parent | 8d947bad093b0920aec2b7cea31da7f723612367 (diff) | |
download | bcm5719-llvm-e04704b9a97a53733b5c3dc43271476d9670e432.tar.gz bcm5719-llvm-e04704b9a97a53733b5c3dc43271476d9670e432.zip |
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.
llvm-svn: 344820
Diffstat (limited to 'libcxx/test/std/thread/thread.threads/thread.thread.class')
-rw-r--r-- | libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp index d419b8cc855..be3fc9c5d1e 100644 --- a/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp +++ b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp @@ -157,8 +157,11 @@ int main() { assert(G::n_alive == 0); assert(!G::op_run); - std::thread t((G())); - t.join(); + { + G g; + std::thread t(g); + t.join(); + } assert(G::n_alive == 0); assert(G::op_run); } @@ -185,8 +188,11 @@ int main() { assert(G::n_alive == 0); assert(!G::op_run); - std::thread t(G(), 5, 5.5); - t.join(); + { + G g; + std::thread t(g, 5, 5.5); + t.join(); + } assert(G::n_alive == 0); assert(G::op_run); } |