diff --git a/Modules/threadmodule.c b/Modules/threadmodule.c index efc5d7f..63c51b0 100644 --- a/Modules/threadmodule.c +++ b/Modules/threadmodule.c @@ -49,6 +49,7 @@ lock_PyThread_acquire_lock(lockobject *self, PyObject *args) return NULL; Py_BEGIN_ALLOW_THREADS + usleep(random() % 50000); i = PyThread_acquire_lock(self->lock_lock, i); Py_END_ALLOW_THREADS diff --git a/Python/thread.c b/Python/thread.c index dd333e8..99b81b8 100644 --- a/Python/thread.c +++ b/Python/thread.c @@ -260,7 +260,7 @@ static int nkeys = 0; /* PyThread_create_key() hands out nkeys+1 next */ static struct key * find_key(int key, void *value) { - struct key *p, *prev_p; + struct key *p, *prev_p, *tmp; long id = PyThread_get_thread_ident(); if (!keymutex) @@ -285,12 +285,16 @@ find_key(int key, void *value) goto Done; } p = (struct key *)malloc(sizeof(struct key)); + memset(p, 0xfe, sizeof(struct key)); if (p != NULL) { p->id = id; p->key = key; p->value = value; - p->next = keyhead; + tmp = keyhead; keyhead = p; + asm volatile ("" : : : "memory"); + usleep(random() % 50000); + keyhead->next = tmp; } Done: PyThread_release_lock(keymutex);