On Thu, 5 Nov 2009, Andrzej K. Haczewski wrote: > 2009/11/5 Nicolas Pitre <nico@xxxxxxxxxxx>: > > On Wed, 4 Nov 2009, Andrzej K. Haczewski wrote: > > > > What about: > > > > typedef struct { > > HANDLE handle; > > void *(*start_routine)(void *); > > void *arg; > > } pthread_t; > > > > DWORD __stdcall windows_thread_start(LPVOID _self) > > { > > pthread_t *self = _self; > > void *ret = self->start_routine(self->arg); > > return (DWORD)ret; > > } > > > > static inline int pthread_create(pthread_t *thread, const void *unused, > > void *(*start_routine)(void *), void *arg) > > { > > thread->handle = CreateThread(NULL, 0, windows_thread_start, > > thread, 0, NULL); > > [...] > > } > > The problem I see is not with pthread_init, but pthread_join. Here's > how it looks: > > int pthread_join(pthread_t thread, void **value_ptr); > > If pthread_t would be a struct, then we can't call pthread_join like > that... Why not? At least gcc is quite happy with such a construct. It probably makes a copy of the stack before passing it though. > At least that's what I though yesterday, but maybe it can be done like > this: > > int win32_pthread_join(pthread_t *thread, void **value_ptr) > { > [...] > } > > #define pthread_join(a, b) win32_pthread_join(&(a), (b)) > > That way we don't need allocations to simulate pthread init/join API Right. Nicolas