mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 06:40:05 +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/qt/manager/thread_manager.hpp> | ||||||
| #include <scwx/util/logger.hpp> | #include <scwx/util/logger.hpp> | ||||||
| 
 | 
 | ||||||
|  | #include <execution> | ||||||
| #include <mutex> | #include <mutex> | ||||||
| 
 | 
 | ||||||
| #include <boost/unordered/unordered_flat_map.hpp> | #include <boost/unordered/unordered_flat_map.hpp> | ||||||
|  | @ -63,11 +64,24 @@ void ThreadManager::StopThreads() | ||||||
| 
 | 
 | ||||||
|    logger_->debug("Stopping threads"); |    logger_->debug("Stopping threads"); | ||||||
| 
 | 
 | ||||||
|    for (auto& thread : p->threadMap_) |    std::for_each(std::execution::par_unseq, | ||||||
|    { |                  p->threadMap_.begin(), | ||||||
|       thread.second->quit(); |                  p->threadMap_.end(), | ||||||
|       thread.second->deleteLater(); |                  [](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(); |    p->threadMap_.clear(); | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat