1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-01-30 02:52:10 +01:00

[util] Fix reference counting for thread objects

Fixes a potential race when threads run out of scope
before the thread function has started.
This commit is contained in:
Philip Rebohle 2018-07-22 02:24:04 +02:00
parent e4c5880ac6
commit 2b8c96fe35
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99

View File

@ -26,6 +26,9 @@ namespace dxvk {
ThreadFn(Proc&& proc)
: m_proc(std::move(proc)) {
// Reference for the thread function
this->incRef();
m_handle = ::CreateThread(nullptr, 0,
ThreadFn::threadProc, this, 0, nullptr);
@ -59,8 +62,9 @@ namespace dxvk {
HANDLE m_handle;
static DWORD WINAPI threadProc(void *arg) {
Rc<ThreadFn> info = reinterpret_cast<ThreadFn*>(arg);
info->m_proc();
auto thread = reinterpret_cast<ThreadFn*>(arg);
thread->m_proc();
thread->decRef();
return 0;
}