This is the mail archive of the
pthreads-win32@sources.redhat.com
mailing list for the pthreas-win32 project.
thread cancellation
- From: Brano Kemen <cameni at manabove dot org>
- To: pthreads <pthreads-win32 at sources dot redhat dot com>
- Date: Mon, 29 Apr 2002 08:56:16 +0200
- Subject: thread cancellation
- Organization: manabove
- Reply-to: cameni at manabove dot org
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