Improve SIGINT handling in multi-threaded programs
The flag remembering whether an Interrupted exception was thrown is now thread-local. Thus, all threads will (eventually) throw Interrupted. Previously, one thread would throw Interrupted, and then the other threads wouldn't see that they were supposed to quit.
This commit is contained in:
		
							parent
							
								
									4f34c40398
								
							
						
					
					
						commit
						ab3ce1cc13
					
				
					 4 changed files with 12 additions and 14 deletions
				
			
		|  | @ -1062,13 +1062,15 @@ void restoreSIGPIPE() | |||
| 
 | ||||
| volatile sig_atomic_t _isInterrupted = 0; | ||||
| 
 | ||||
| thread_local bool interruptThrown = false; | ||||
| 
 | ||||
| void _interrupted() | ||||
| { | ||||
|     /* Block user interrupts while an exception is being handled.
 | ||||
|        Throwing an exception while another exception is being handled | ||||
|        kills the program! */ | ||||
|     if (!std::uncaught_exception()) { | ||||
|         _isInterrupted = 0; | ||||
|     if (!interruptThrown && !std::uncaught_exception()) { | ||||
|         interruptThrown = true; | ||||
|         throw Interrupted("interrupted by the user"); | ||||
|     } | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue