Re: [Gc] Re: Re: sigset_t not defined for win32-pthreads

Ivan Maidanski ivmai at mail.ru
Thu Sep 2 22:15:41 PDT 2010


Hi!

Thu, 2 Sep 2010 11:35:04 +0000 (UTC) windev92 <windev92 at yahoo.fr>:

> I'm using 7.1, but it is finally a race condition, not a problem per se.
> Using GC_CreateThread, we don't have this side effect, thread GC_start function
> is called quickly and thread is hence registered.
> 
> With pthread, it's not the case(on Win32 at least on my machine)
> The code below shows the problem. 
> 
> pthread_t t;
> int code;
>
> if((code = pthread_create(&t, 0, pthreadfn, 0))!= 0)
> {
> 	return -1;
> }
> 	
> GC_gcollect();
> 
> GC_gcollect() doesn't suspend the thread when called straight after. pthreadfn
> should be called first, to make sure its thread is registered.

Nowhere in specs it is said that the thread is registered before pthread_create() returns (but, for some reasons, non-win32 GC_pthread_create does).

> 
> Do you have a sample code showing how to do this with *pthreads*?

See pthread_create in pthread_support.c, it uses sema_post/wait for doing the same thing.

> Equivalent of :
> 
> hThread = GC_CreateThread(NULL,0, threadFn,&lszThreadParam,0,&dwGenericThread);
> WaitForSingleObject(g_startedThreadEvent,INFINITE);
> GC_gcollect();
> 
> DWORD WINAPI threadFn(LPVOID iValue)
> {
>    SetEvent(g_startedThreadEvent);
> }
> 
> Thanks


More information about the Gc mailing list