mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	gh-105699: Use a Thread-Local Variable for PKGCONTEXT (gh-105740)
This fixes a race during import. The existing _PyRuntimeState.imports.pkgcontext is shared between interpreters, and occasionally this would cause a crash when multiple interpreters were importing extensions modules at the same time. To solve this we add a thread-local variable for the value. We also leave the existing state (and infrequent race) in place for platforms that do not support thread-local variables.
This commit is contained in:
		
							parent
							
								
									fcf0647cf2
								
							
						
					
					
						commit
						b87d288275
					
				
					 4 changed files with 24 additions and 1 deletions
				
			
		|  | @ -58,6 +58,7 @@ def _ind(text, level=1, edges='both'): | |||
|             extern | | ||||
|             register | | ||||
|             static | | ||||
|             _Thread_local | | ||||
|             typedef | | ||||
| 
 | ||||
|             const | | ||||
|  | @ -137,7 +138,7 @@ def _ind(text, level=1, edges='both'): | |||
| ####################################### | ||||
| # variable declarations | ||||
| 
 | ||||
| _STORAGE = 'auto register static extern'.split() | ||||
| _STORAGE = 'auto register static extern _Thread_local'.split() | ||||
| STORAGE_CLASS = rf'(?: \b (?: {" | ".join(_STORAGE)} ) \b )' | ||||
| TYPE_QUALIFIER = r'(?: \b (?: const | volatile ) \b )' | ||||
| PTR_QUALIFIER = rf'(?: [*] (?: \s* {TYPE_QUALIFIER} )? )' | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Eric Snow
						Eric Snow