Skip to content

Commit

Permalink
Merge pull request #953 from leapmotion/test-corethread
Browse files Browse the repository at this point in the history
Extend unit tests for CoreThread behaviors
  • Loading branch information
yeswalrus committed May 22, 2016
2 parents 287dea7 + 6a68811 commit 6eb4f66
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/autowiring/BasicThread.cpp
Expand Up @@ -130,8 +130,9 @@ bool BasicThread::OnStart(void) {
m_running = true;
m_wasStarted = true;

// Place the new thread entity directly in the space where it goes to avoid
// any kind of races arising from asynchronous access to this space
// Place the new thread entity directly in the space where it goes. This
// enables us to decide in advance the exact location in memory where the
// object will be stored.
auto outstanding = GetOutstanding();
m_state->m_thisThread.~thread();
new (&m_state->m_thisThread) std::thread(
Expand Down
7 changes: 6 additions & 1 deletion src/autowiring/test/CoreThreadTest.cpp
Expand Up @@ -622,22 +622,27 @@ TEST_F(CoreThreadTest, LambdaHoldAfterTermination) {
ctxt->Initiate();

std::weak_ptr<CoreContext> childWeak;
auto teardownCalled = std::make_shared<bool>(false);

{
AutoCreateContext child;
AutoRequired<CoreThread> mct{ child };

// This is the critical piece which generates a hold on `child` after teardown
mct->AddTeardownListener([mct, child] {
mct->AddTeardownListener([mct, child, teardownCalled] {
*mct += [child] {};
*teardownCalled = true;
});

child->Initiate();
*mct += [] {};
mct->Barrier();
ASSERT_GE(1U, mct->GetDispatchQueueLength()) << "Dispatch queue had lingering entries after barrier";
child->SignalShutdown();
childWeak = child;
child->Wait();
}
ASSERT_TRUE(*teardownCalled) << "Teardown listener was not called as expected";
ASSERT_TRUE(childWeak.expired()) << "Child context leaked due to lambda pending in teardown";
}

Expand Down

0 comments on commit 6eb4f66

Please sign in to comment.