File tree Expand file tree Collapse file tree 2 files changed +24
-14
lines changed
Server/mods/deathmatch/logic Expand file tree Collapse file tree 2 files changed +24
-14
lines changed Original file line number Diff line number Diff line change @@ -422,6 +422,7 @@ CGame::~CGame()
422
422
SAFE_DELETE (m_pASE);
423
423
SAFE_RELEASE (m_pHqComms);
424
424
CSimControl::Shutdown ();
425
+ CThreadPool::getDefaultThreadPool ().shutdown ();
425
426
426
427
// Clear our global pointer
427
428
g_pGame = NULL ;
Original file line number Diff line number Diff line change @@ -71,26 +71,35 @@ namespace SharedUtil
71
71
return res;
72
72
}
73
73
74
- ~CThreadPool ()
74
+ void shutdown ()
75
75
{
76
+ if (m_exit)
77
+ return ;
78
+
79
+ // Ensure every thread receives the exit state, and discard all remaining tasks.
80
+ {
81
+ std::unique_lock<std::mutex> lock (m_mutex);
82
+ m_exit = true ;
83
+
84
+ while (!m_tasks.empty ())
85
+ {
86
+ // Run each task but skip execution of the actual function (-> just delete the task)
87
+ auto task = std::move (m_tasks.front ());
88
+ task (true );
89
+ }
90
+ }
91
+
76
92
// Notify all threads to exit
77
- m_exit = true ;
78
93
m_cv.notify_all ();
94
+
79
95
// Wait for threads to end
80
96
for (std::thread& worker : m_vecThreads)
81
- {
82
97
worker.join ();
83
- }
84
- // Cleanup
85
- do
86
- {
87
- if (m_tasks.empty ())
88
- break ;
89
- // Run each task but skip execution of the actual
90
- // function (-> just delete the task)
91
- auto task = std::move (m_tasks.front ());
92
- task (true );
93
- } while (true );
98
+ }
99
+
100
+ ~CThreadPool ()
101
+ {
102
+ shutdown ();
94
103
}
95
104
96
105
static CThreadPool& getDefaultThreadPool ()
You can’t perform that action at this time.
0 commit comments