From: Pierre Habouzit Date: Sat, 1 Dec 2007 14:05:20 +0000 (+0100) Subject: we must copy the closure temporarily. X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=c9a8143558309158b760ca75a36d7193d140c12b;p=apps%2Fpfixtools.git we must copy the closure temporarily. Signed-off-by: Pierre Habouzit --- diff --git a/threads.c b/threads.c index 249a123..16d0518 100644 --- a/threads.c +++ b/threads.c @@ -41,8 +41,8 @@ static struct { int count, size; } morgue; -struct thread_foo { - void *(*fun)(int fd, void *); +struct job_closure { + void *(*f)(int, void*); int fd; void *data; }; @@ -59,19 +59,21 @@ void thread_register_dead(void *tid) static void *thread_wrapper(void *arg) { - struct thread_foo *foo = arg; + struct job_closure *closure = arg; void *res; + pthread_cleanup_push(thread_register_dead, (void *)pthread_self()); - res = (*foo->fun)(foo->fd, foo->data); + res = (*closure->f)(closure->fd, closure->data); pthread_cleanup_pop(1); + p_delete(&closure); return res; } int thread_launch(void *(*f)(int, void *), int fd, void *data) { - struct thread_foo foo = { f, fd, data }; + struct job_closure closure = { .f = f, .fd = fd, .data = data }; pthread_t t; - return pthread_create(&t, NULL, &thread_wrapper, &foo); + return pthread_create(&t, NULL, &thread_wrapper, p_dup(&closure, 1)); } void threads_join(void)