mirror of
https://github.com/sockspls/badfish
synced 2025-04-29 16:23:09 +00:00
When exiting wake up all threads at once
It seems we have a very rare crash under Linux, once every 10K games without this patch. Is faster to wake up all the threads, especially on SMP, where the threads can then exit in parallel while the main thread is waiting for the next one to terminate. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
63a04134d0
commit
83d8fe2d59
1 changed files with 9 additions and 4 deletions
|
@ -192,14 +192,19 @@ void ThreadsManager::init() {
|
|||
|
||||
void ThreadsManager::exit() {
|
||||
|
||||
for (int i = 0; i < MAX_THREADS; i++)
|
||||
{
|
||||
// Wake up all the slave threads and wait for termination
|
||||
if (i != 0)
|
||||
// Wake up all the slave threads at once. This is faster than "wake and wait"
|
||||
// for each thread and avoids a rare crash once every 10K games under Linux.
|
||||
for (int i = 1; i < MAX_THREADS; i++)
|
||||
{
|
||||
threads[i].do_terminate = true;
|
||||
threads[i].wake_up();
|
||||
}
|
||||
|
||||
for (int i = 0; i < MAX_THREADS; i++)
|
||||
{
|
||||
if (i != 0)
|
||||
{
|
||||
// Wait for slave termination
|
||||
#if defined(_MSC_VER)
|
||||
WaitForSingleObject(threads[i].handle, 0);
|
||||
CloseHandle(threads[i].handle);
|
||||
|
|
Loading…
Add table
Reference in a new issue