Re: Best Practice For Forcing A Thread To Unblock Itself
- From: "Arnaud Debaene" <adebaene@xxxxxxxxxxxxxxxx>
- Date: Tue, 1 Nov 2005 22:14:36 +0100
Le Chaud Lapin wrote:
> Jochen Kalmbach [MVP] wrote:
>> Hi Le!
> Hi Jochen.
>
>> SetEvent ?
>> And thread B should always wait with "WaitForMultipleObjects"...
>
> There lies the problem. I was going to insist that thread B always
> uses WaitForMultipleObjects, but the problem still remains with the
> select() function in sockets. Right now I am having thread A close
> the socket that B is select()'ing on to force B to unblock.
You should use the WSA* "extended" winsock API instead of the Berkley style
API. This would allow you to use WSAWaitForMultipleEvents, passing to it
both the socket and a "signal to exit" event.
> Guess I will check to
> see what POSIX offers like WaitForMultipleObjects.
Nothing : Under POSIX, you would use signals to, well to *signal* the thread
to stop ;-). Note that you can also use a similar mechanism in Windows, with
a user-mode APC (see QueueUserAPC). This needs your waiting thread to be in
an alertable wait state, but this is no problem with
WSAWaitForMultipleEvents.
Still another option would be to call WSACancelBlockingCall on (one of) the
socket(s) in thread A and to check the return value of select in thread B.
Anyway, generally speaking, when complex synchronisation take place, it is
generally a bad idea to try to map the Unix style idioms to Win32 : they
support different mechanisms, and you should try to take advantage of those
mechanisms : In one hand, Unix has signals (which you can more or less
emulate with APC, but in much more specific ad limited cases). On the other
hand, Win32 has non blocking IO, which should be the preferred choice when
having high-performance or complex synchronisation needs.
> -Le Chaud Lapin-
Ah bon??? Sacrés gaulois ;-)
Arnaud
MVP - VC
.
- References:
- Best Practice For Forcing A Thread To Unblock Itself
- From: Le Chaud Lapin
- Re: Best Practice For Forcing A Thread To Unblock Itself
- From: Jochen Kalmbach [MVP]
- Re: Best Practice For Forcing A Thread To Unblock Itself
- From: Le Chaud Lapin
- Best Practice For Forcing A Thread To Unblock Itself
- Prev by Date: Re: Best Practice For Forcing A Thread To Unblock Itself
- Next by Date: Re: passing username/passwd between two processes securely...
- Previous by thread: Re: Best Practice For Forcing A Thread To Unblock Itself
- Next by thread: Re: Best Practice For Forcing A Thread To Unblock Itself
- Index(es):
Relevant Pages
|