Skip to content

Commit

Permalink
coreinit: Fix race condition that causes crash (#1138)
Browse files Browse the repository at this point in the history
  • Loading branch information
goeiecool9999 authored Mar 26, 2024
1 parent fa4ad9b commit 111e383
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Cafe/OS/libs/coreinit/coreinit_Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1159,9 +1159,11 @@ namespace coreinit
#include <sys/prctl.h>

std::vector<pid_t> g_schedulerThreadIds;
std::mutex g_schedulerThreadIdsLock;

std::vector<pid_t>& OSGetSchedulerThreadIds()
{
std::lock_guard schedulerThreadIdsLockGuard(g_schedulerThreadIdsLock);
return g_schedulerThreadIds;
}
#endif
Expand All @@ -1183,7 +1185,10 @@ namespace coreinit
}

pid_t tid = gettid();
g_schedulerThreadIds.emplace_back(tid);
{
std::lock_guard schedulerThreadIdsLockGuard(g_schedulerThreadIdsLock);
g_schedulerThreadIds.emplace_back(tid);
}
#endif

t_schedulerFiber = Fiber::PrepareCurrentThread();
Expand Down Expand Up @@ -1238,7 +1243,10 @@ namespace coreinit
sSchedulerThreads.clear();
g_schedulerThreadHandles.clear();
#if BOOST_OS_LINUX
g_schedulerThreadIds.clear();
{
std::lock_guard schedulerThreadIdsLockGuard(g_schedulerThreadIdsLock);
g_schedulerThreadIds.clear();
}
#endif
// clean up all fibers
for (auto& it : g_idleLoopFiber)
Expand Down

0 comments on commit 111e383

Please sign in to comment.