This is an archive of the discontinued LLVM Phabricator instance.

[libc++][test] Remove non-portable assumption that thread's constructor allocates with ::new
ClosedPublic

Authored by CaseyCarter on Aug 16 2018, 11:38 AM.

Diff Detail

Event Timeline

CaseyCarter created this revision.Aug 16 2018, 11:38 AM
EricWF added inline comments.Oct 12 2018, 9:39 PM
test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp
121

Why?

174

I'm not sure I understand this change either.

EricWF requested changes to this revision.Oct 12 2018, 9:39 PM

Requesting changes to move this out of my TODO review queue.

This revision now requires changes to proceed.Oct 12 2018, 9:39 PM
CaseyCarter added a comment.EditedOct 26 2018, 11:03 AM

I'll put this explanation in the comments and push a change.

EDIT: Sorry for the slow response: I didn't get a notification from Phabricator that you'd commented or requested changes. I need to check my settings, I suppose.

test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp
121

main non-portably assumes that thread creation results in at least one call to ::operator new. This change fixes that assumption by counting the number of calls to ::operator new here for creation of a do-nothing thread, and communicating that count to main via numAllocs.

174

If thread creation in test_throwing_new_during_thread_creation resulted in 0 calls to ::operator new, the expectation is that the same will occur here when we create a thread. If ::operator new isn't called, it can't throw the exception this test is expecting to catch.

Clarify use of numAllocs.

EricWF accepted this revision.Apr 27 2019, 9:51 PM

LGTM minus inline comments.

test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp
174

Since libc++ seems to allocate, could we sanity test that?

// The test below is non-portable because it expects `std::thread` to call `new`, which may not be the case for all implementations.
LIBCPP_ASSERT(numAllocs > 0); // libc++ should call new. Sanity check `numAllocs`.
if (numAllocs > 0) { ... }
This revision is now accepted and ready to land.Apr 27 2019, 9:51 PM
This revision was automatically updated to reflect the committed changes.