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 @@ -421,6 +421,7 @@ CGame::~CGame()
421421 SAFE_DELETE (m_pASE);
422422 SAFE_RELEASE (m_pHqComms);
423423 CSimControl::Shutdown ();
424+ CThreadPool::getDefaultThreadPool ().shutdown ();
424425
425426 // Clear our global pointer
426427 g_pGame = NULL ;
Original file line number Diff line number Diff line change @@ -71,26 +71,35 @@ namespace SharedUtil
7171 return res;
7272 }
7373
74- ~CThreadPool ()
74+ void shutdown ()
7575 {
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+
7692 // Notify all threads to exit
77- m_exit = true ;
7893 m_cv.notify_all ();
94+
7995 // Wait for threads to end
8096 for (std::thread& worker : m_vecThreads)
81- {
8297 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 ();
94103 }
95104
96105 static CThreadPool& getDefaultThreadPool ()
You can’t perform that action at this time.
0 commit comments