Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thread instantiation must happen via placement operations #49

Merged
merged 1 commit into from
Aug 15, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/autowiring/BasicThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,10 @@ bool BasicThread::Start(std::shared_ptr<Object> outstanding) {
m_state->m_stateCondition.notify_all();
}

// Kick off a thread and return here
m_state->m_thisThread = std::thread(
// 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
m_state->m_thisThread.~thread();
new (&m_state->m_thisThread) std::thread(
[this, outstanding] () mutable {
this->DoRun(std::move(outstanding));
}
Expand Down
2 changes: 1 addition & 1 deletion src/autowiring/CoreThreadWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void SetThreadName(DWORD dwThreadID, LPCSTR szThreadName)
}

void BasicThread::SetCurrentThreadName(void) const {
DWORD threadId = ::GetThreadId(static_cast<HANDLE>(m_state->m_thisThread.native_handle()));
DWORD threadId = ::GetThreadId(m_state->m_thisThread.native_handle());
::SetThreadName(threadId, m_name);
}

Expand Down