mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 12:10:06 +00:00 
			
		
		
		
	Properly manage QThread termination
This commit is contained in:
		
							parent
							
								
									8f7076cd09
								
							
						
					
					
						commit
						f976e88359
					
				
					 1 changed files with 19 additions and 5 deletions
				
			
		|  | @ -1,6 +1,7 @@ | |||
| #include <scwx/qt/manager/thread_manager.hpp> | ||||
| #include <scwx/util/logger.hpp> | ||||
| 
 | ||||
| #include <execution> | ||||
| #include <mutex> | ||||
| 
 | ||||
| #include <boost/unordered/unordered_flat_map.hpp> | ||||
|  | @ -63,11 +64,24 @@ void ThreadManager::StopThreads() | |||
| 
 | ||||
|    logger_->debug("Stopping threads"); | ||||
| 
 | ||||
|    for (auto& thread : p->threadMap_) | ||||
|    { | ||||
|       thread.second->quit(); | ||||
|       thread.second->deleteLater(); | ||||
|    } | ||||
|    std::for_each(std::execution::par_unseq, | ||||
|                  p->threadMap_.begin(), | ||||
|                  p->threadMap_.end(), | ||||
|                  [](auto& thread) | ||||
|                  { | ||||
|                     logger_->trace("Stopping thread: {}", thread.first); | ||||
| 
 | ||||
|                     thread.second->quit(); | ||||
|                     if (!thread.second->wait(5000)) | ||||
|                     { | ||||
|                        logger_->warn("Terminating thread: {}", thread.first); | ||||
| 
 | ||||
|                        thread.second->terminate(); | ||||
|                        thread.second->wait(); | ||||
|                     } | ||||
| 
 | ||||
|                     delete thread.second; | ||||
|                  }); | ||||
| 
 | ||||
|    p->threadMap_.clear(); | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat