Re: Using SetConsoleCtrlHandler
- From: "Marc Sherman" <masherman1970@xxxxxxxxx>
- Date: Thu, 7 Jun 2007 12:08:20 -0400
Assuming the signal handler does the minimum (ie. set a global, set an
event) and never tries to acquire a lock (explicitly or implicitly), would
there still be a problem in a multithreaded POSIX app?
"Alexander Grigoriev" <alegr@xxxxxxxxxxxxx> wrote in message
news:u0k46rRqHHA.1208@xxxxxxxxxxxxxxxxxxxxxxx
A BIG BIG problem with asynchronous notifications is that in a
multithreaded process there is NO reliable interrupt point, other than
explicitly provided (alertable wait). Only a single-threaded POSIX
application can be interrupted at a random instruction without ill effects.
"Marc Sherman" <masherman1970@xxxxxxxxx> wrote in message
news:O1XaNaQqHHA.4520@xxxxxxxxxxxxxxxxxxxxxxx
From "Windows Internals, 4th Edition" (p. 108)
"The POSIX subsystem uses kernel-mode APCs to emulate the delivery of
POSIX signals to POSIX processes".
Also from the same page:
"Kernel mode APCs interrupt a thread and execute a procedure without the
thread's intervention or consent".
That tells me they would behave like a UNIX developer would expect.
Marc
"Tony Proctor" <tony_proctor@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
message news:eEO3XfOqHHA.3296@xxxxxxxxxxxxxxxxxxxxxxx
...actually, I don't suppose anyone knows how things like SIGINT are
implemented in the POSIX sub-system under Windows. Do they even work
like a
UNIX developer would expect?
Tony Proctor
"Gary Chanson" <gchanson@xxxxxxxxxxxxxxxx> wrote in message
news:O$s$jsDqHHA.4132@xxxxxxxxxxxxxxxxxxxxxxx
My solution for a similar situation was to redirect the exceptionthe
to
appropriate thread using a User APC. In my case, I can be reasonablyalternative.
certain that the task will enter an alertable state within a reasonable
time, so this works very nicely and is a lot cleaner they your
message
--
- Gary Chanson (Windows SDK MVP)
- Abolish Public Schools
"Tony Proctor" <tony_proctor@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
news:eFnX5$BqHHA.1148@xxxxxxxxxxxxxxxxxxxxxxxASTs)
Windows is not very good at handling this sort of asynchronouson
interrupt
a single thread Emmanuel (i.e. similar to UNIX signals, or even VMS
http://groups.google.ie/group/microsoft.public.win32.programmer.kernel/browse_frm/thread/608ad10204f76515/1e175f06dca6106f?hl=en#1e175f06dca6106f
The question has been asked before:
and
I've even found myself in the same boat in trying to port a language,
apiits framework, to the Windows O/S. In the end, I suspended theread
thread,
its context, redirected it to a point that would generate the
required
exception, and then released it. Surprisingly, it worked OK in
practice
(although not on Alpha AXP H/W) but there were a few issues with
win32
usingcalls that had to be addressed (mentioned in that old thread)
Tony Proctor
"Emmanuel Stapf [ES]" <manus@xxxxxxxxxxxxxxxxx> wrote in message
news:uQhAUi9pHHA.1144@xxxxxxxxxxxxxxxxxxxxxxx
Hi,Ctrl+C. No
I've a console single threaded application and I'm trying to catch
a
matter if I use SetConsoleCtrlHandler or a signal handler, my codehandle
to
this gets called in another thread. Is there a way to have thecalled
handler
from the main thread?
In the code below, simply comment the call to `signal' or to
`SetConsoleCtrlHandler' to observe the similar behavior. On Unix,
`signal', it is called from the same thread.
Thanks for any highlight,
Manu
PS: this is shown by the code:
#include <windows.h>
#include <stdio.h>
#include <signal.h>
BOOL CtrlHandler( DWORD fdwCtrlType )
{
switch( fdwCtrlType ) {
case CTRL_C_EVENT:
printf( "Ctrl-C event\n\n" );
return TRUE;
default:
return FALSE;
}
}
void handler (int sig) {
printf ("From Signal\n");
signal (SIGINT, handler);
}
void main( void )
{
signal (SIGINT, handler);
//SetConsoleCtrlHandler( (PHANDLER_ROUTINE) CtrlHandler, TRUE );
printf("Use Ctrl+C to see what is going on.\n" );
while( 1 ){ }
}
.
- References:
- Using SetConsoleCtrlHandler
- From: Emmanuel Stapf [ES]
- Re: Using SetConsoleCtrlHandler
- From: Tony Proctor
- Re: Using SetConsoleCtrlHandler
- From: Gary Chanson
- Re: Using SetConsoleCtrlHandler
- From: Tony Proctor
- Re: Using SetConsoleCtrlHandler
- From: Marc Sherman
- Re: Using SetConsoleCtrlHandler
- From: Alexander Grigoriev
- Using SetConsoleCtrlHandler
- Prev by Date: Re: Using SetConsoleCtrlHandler
- Next by Date: Re: Common place to write application data
- Previous by thread: Re: Using SetConsoleCtrlHandler
- Next by thread: Re: Using SetConsoleCtrlHandler
- Index(es):
Relevant Pages
|