cancellation API

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

cancellation API

Roger Pack
After a bit of googling, i was still a bit confused.  Does the
win32-pthreads api support cancellation for things like recv() from
sockets or not? (I assume the standard pthreads does?)
Thank you, just wondering.
-roger-
Reply | Threaded
Open this post in threaded view
|

RE: cancellation API

Mark Pizzolato - pthreads - win32
On Friday, December 20, 2013 at 9:50 AM, Roger Park wrote:
> After a bit of googling, i was still a bit confused.  Does the win32-pthreads api
> support cancellation for things like recv() from sockets or not? (I assume the
> standard pthreads does?) Thank you, just wondering.

There is no special awareness of thread context from within the recv() (or any networking APIs).  So, canceling would be potentially problematic.  However, from my experience, if another thread closes the socket which the thread you're concerned with is reading on, the read will complete with an error.  The reading thread can then clean up and exit on its own.

- Mark

Reply | Threaded
Open this post in threaded view
|

Re: cancellation API

Roger Pack
It might be interesting to "fallback" (in the case of Vista+) to using
CancelSynchronousIo if there is no QueueUserAPCEx available.  FWIW.
-roger-

On 12/30/13, Roger Pack <[hidden email]> wrote:

> On 12/20/13, Mark Pizzolato - pthreads - win32
> <[hidden email]> wrote:
>> On Friday, December 20, 2013 at 9:50 AM, Roger Park wrote:
>>> After a bit of googling, i was still a bit confused.  Does the
>>> win32-pthreads api
>>> support cancellation for things like recv() from sockets or not? (I
>>> assume
>>> the
>>> standard pthreads does?) Thank you, just wondering.
>>
>> There is no special awareness of thread context from within the recv()
>> (or
>> any networking APIs).  So, canceling would be potentially problematic.
>> However, from my experience, if another thread closes the socket which
>> the
>> thread you're concerned with is reading on, the read will complete with
>> an
>> error.  The reading thread can then clean up and exit on its own.
>
> It appears from the source that win32-pthreads defines PTHREAD_CANCEL
> but then doesn't actually *do* any cancelling unless you happen to
> have this 3rd party library "QueueUserAPCEx" which appears to require
> a kernel level driver to have been loaded [?] so feels somewhat
> violent...
> FWIW.
> -roger-
>
> Pthreads-win32 will automatically detect if the QueueUserAPCEx DLL
> QuserEx.DLL is available and whether the driver AlertDrv.sys is
> loaded. If it is not available, pthreads-win32 will simulate async
> cancelation, which means that it can async cancel only threads that
> are runnable. The simulated async cancellation cannot cancel blocked
> threads.
>