This is an archive of the discontinued LLVM Phabricator instance.

[libcxx] Add Atomic test helper and fix TSAN failures.
ClosedPublic

Authored by EricWF on Jul 8 2015, 4:05 PM.

Details

Summary

This patch attempts to fix the last 3 TSAN failures on the libc++ bot (http://lab.llvm.org:8011/builders/libcxx-libcxxabi-x86_64-linux-ubuntu-tsan/builds/143). This patch also adds a Atomic test type that can be used where <atomic> cannot.

wait.exception.pass.cpp and wait_for.exception.pass.cpp were failing because the test replaced std::terminate with std::exit. std::exit would asynchronously run the TLS and static destructors and this would cause a race condition. See PR22606 and D8802 for more details.

This is fixed by using _Exit to prevent cleanup.

notify_all_at_thread_exit.pass.cpp exercises the same race condition but for different reasons. I fixed this test by manually joining the thread before beginning program termination.

Diff Detail

Event Timeline

EricWF updated this revision to Diff 29291.Jul 8 2015, 4:05 PM
EricWF retitled this revision from to [libcxx] Add Atomic test helper and fix TSAN failures..
EricWF updated this object.
EricWF added a reviewer: mclow.lists.
EricWF added a subscriber: cfe-commits.
mclow.lists edited edge metadata.Jul 13 2015, 1:10 PM

Should these tests go into the std/ hierarchy, or the libcxx/ hierarchy?

EricWF accepted this revision.Jul 28 2015, 10:24 AM
EricWF added a reviewer: EricWF.

Should these tests go into the std/ hierarchy, or the libcxx/ hierarchy?

They belong in std/. There is a remark on each of the following wait* methods that states

[thread.condition.condvarany]
Postcondition: lock.owns_lock() is true and lock.mutex() is locked by the calling thread.
Remarks: If the function fails to meet the postcondition, std::terminate() shall be called

This revision is now accepted and ready to land.Jul 28 2015, 10:24 AM
EricWF updated this revision to Diff 32454.Aug 18 2015, 2:37 PM
EricWF edited edge metadata.

Add more explanation to the wait tests.

EricWF updated this revision to Diff 32473.Aug 18 2015, 4:27 PM

Fix more failing TSAN tests.

EricWF closed this revision.Aug 18 2015, 4:30 PM
test/std/thread/thread.condition/thread.condition.condvar/notify_one.pass.cpp