This is the mail archive of the mailing list for the pthreas-win32 project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

thread cancellation

I had the same problems as described in 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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]