Re: [PATCH] MSVC: Windows-native implementation for subset of Pthreads API

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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... 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

> And thread creation is a relatively rare event compared to e.g. mutex
> lock/unlock, so the indirection shouldn't be noticeable.  For the same
> reason, I also think that you could make pthread_create() and
> pthread_join() into a C file instead of being inlined which would reduce
> the code footprint at every call site, and allow for only one instance
> of windows_thread_start() which could then be made static.

Yeah, I'll factor that out to separate file.

--
Andrzej
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]