public inbox for pthreads-win32@sourceware.org
 help / color / mirror / Atom feed
* thread cancellation
@ 2002-04-28 23:56 Brano Kemen
  0 siblings, 0 replies; only message in thread
From: Brano Kemen @ 2002-04-28 23:56 UTC (permalink / raw)
  To: pthreads

I had the same problems as described in http://sources.redhat.com/ml/pthreads-win32/2001/msg00037.html and in the FAQ, with cancellation of a thread that is blocking on an accept() call. The problem is that the 
thread won't be cancelled while it waits for input, so for example you had to make a connect() to the socket blocking the thread in order to get it to execute exception throwing routine. This was unacceptable for me, 
so I went searching for another option, and this is what i've found:
- there's undocumented funcion in the win32 kernel - AlertThread () - that resumes thread waiting for input
    typedef unsigned long (__stdcall *t_AlertThread) (HANDLE thread);

- so now i do this

    // on startup
    HINSTANCE h = LoadLibrary ("ntdll.dll");
    t_AlertThread alert_thread = (t_AlertThread) GetProcAddress (h, "NtAlertThread");

    // cancellation
    pthread_cancel (tid);
    alert_thread (pthread_getw32threadhandle_np (tid));
                
    pthread_join (tid, &p);

I use it on w2k for threads waiting on sockets, so it would be needed to check this for other versions of windows (and other reasons when thread blocks).
Can this get it into the pthreads lib or at least into the FAQ?

Brano Kemen



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-04-29  6:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-28 23:56 thread cancellation Brano Kemen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).