Re[2]: [Gc] RE: GC + Windows Mobile + Threads + Patch for WINCE

Ivan Maidanski ivmai at mail.ru
Fri Aug 21 10:07:31 PDT 2009


Hi!

Henning Makholm <makholm at octoshape.com> wrote:
> > Unfortunately, the function "GetCurrentThread" kept returning the same handles.
> 
> GetCurrentThread is documented to return a pseudo-handle that means
> "whichever thread passes the psedo handle as an argument to a system call".
> The pseudo-handle is the same no matter which thread calls the function.
> 
> That is the documented behavior even for Windows CE:
> 
> MSDN> The function cannot be used by one thread to create a handle that
> MSDN> can be used by other threads to refer to the first thread. The
> MSDN> handle is always interpreted as referring to the thread that is
> MSDN> using it.
> 
> http://msdn.microsoft.com/en-us/library/ms908251.aspx

> On the other hand Windows CE documents that the value of
> GetCurrentThreadId() is actually a handle for the thread
> -- which is not true in ordinary win32.

Yes, thanks, I've looked again in kfuncs.c:

#ifndef _CRTBLD
_inline HANDLE GetCurrentThread(void) {
        return ((HANDLE)(SH_CURTHREAD+SYS_HANDLE_BASE)); // is a const (65)
}
#endif

And another WinCE MSDN doc says thread handles can't be passed to DuplicateHandle(): http://msdn.microsoft.com/en-us/library/ms885208.aspx

But how can we get a thread handle visible from another thread? Even if we use handles returned CreateThread() (which is a bad idea because of the user shouldn't detach it and this won't work for GC_register_my_thread()), we still need to get main thread handle (to be able to stop it from another thread). Any ideas? Does DuplicateHandle() really always fail to duplicate handles?

> 
> --
> Henning Makholm
> Octoshape ApS

Bye.


More information about the Gc mailing list