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

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

 



On Wed, 4 Nov 2009, Andrzej K. Haczewski wrote:

> Erik Faye-Lund pisze:
> > Couldn't the windows version of pthread_create have a wrapper
> > function, that corrected the calling convention, much like the
> > function run_thread that start_async in run-command.c has?
> 
> Can't be done without allocations. I'd have to pass to that wrapping
> thread function an address of original function *and* an original
> argument, and there's no way to pack that as one void*.

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);
        [...]
}

?

Sure this will use 8 to 16 more bytes per thread, but we're dealing with 
a rather small number of threads anyway (more threads than the number of 
CPU cores is useless) making this extra memory usage rather 
insignificant compared to the many megabytes of RAM the rest of the code 
is using.  The advantage is full compatibility with the native pthread 
interface git is using at the source level while still being much 
lighter than a full blown pthread implementation.

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.


Nicolas
--
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]