comparison Python/thread.c @ 47664:db99f8752710 legacy-trunk

#1683 prevent forking from interfering in threading storage This should prevent some test_multiprocessing failures
author Benjamin Peterson <benjamin@python.org>
date Fri, 13 Jun 2008 00:09:47 +0000
parents 132d908471c8
children a8a8232cb541
comparison
equal deleted inserted replaced
47659:6585fd1d9ad7 47664:db99f8752710
379 q = &p->next; 379 q = &p->next;
380 } 380 }
381 PyThread_release_lock(keymutex); 381 PyThread_release_lock(keymutex);
382 } 382 }
383 383
384 /* Forget everything not associated with the current thread id.
385 * This function is called from PyOS_AfterFork(). It is necessary
386 * because other thread ids which were in use at the time of the fork
387 * may be reused for new threads created in the forked process.
388 */
389 void
390 PyThread_ReInitTLS(void)
391 {
392 long id = PyThread_get_thread_ident();
393 struct key *p, **q;
394
395 if (!keymutex)
396 return;
397
398 /* As with interpreter_lock in PyEval_ReInitThreads()
399 we just create a new lock without freeing the old one */
400 keymutex = PyThread_allocate_lock();
401
402 /* Delete all keys which do not match the current thread id */
403 q = &keyhead;
404 while ((p = *q) != NULL) {
405 if (p->id != id) {
406 *q = p->next;
407 free((void *)p);
408 /* NB This does *not* free p->value! */
409 }
410 else
411 q = &p->next;
412 }
413 }
414
384 #endif /* Py_HAVE_NATIVE_TLS */ 415 #endif /* Py_HAVE_NATIVE_TLS */