DosSetSigHandler
#define INCL_DOSSIGNALS
USHORT rc = DosSetSigHandler(Routine, PrevAddress, PrevAction, Action,
SigNumber);
PFNSIGHANDLER Routine; /* Signal handler */
PFNSIGHANDLER FAR * PrevAddress; /* Previous handler (returned) */
PUSHORT PrevAction; /* Previous action (returned) */
USHORT Action; /* Indicate request type */
USHORT SigNumber; /* Signal number of interest */
USHORT rc; /* return code */
Example
The following example illustrates the use of a user-defined flag to signal
time-critical events. The main thread installs a routine, named
FlagA_Handler(), as the signal handler for user-defined Flag A. It then
creates a thread and blocks on a reserved RAM semaphore; this thread
obtains its process ID and signals the main thread via Flag A. The main
thread responds by executing the signal handler.
#define INCL_DOSPROCESS
#define INCL_DOSSIGNALS
#define INCL_DOSERRORS
#include <os2.h>
#define TIMEOUT 5000L
TID ThreadID;
BYTE ThreadStack[4000];
VOID APIENTRY FlagA_Handler(arg1, arg2) /* Define signal handler */
USHORT arg1;
USHORT arg2;
{
printf("Handler for Flag A now running.\n");
return;
}
VOID APIENTRY Thread_A()
{
PIDINFO PidInfo;
USHORT FlagArg;
USHORT rc;
DosGetPID(&PidInfo);
printf("Process ID is %d\n", PidInfo.pid);
if(!(rc = DosFlagProcess(PidInfo.pid,
FLGP_PID,
PFLG_A,
FlagArg)))
printf("FlagA signal sent from ThreadA to main thread.\n");
else
printf("FlagProcess rc is %d\n", rc)/* Error processing on rc */;
DosExit(EXIT_THREAD, /* Action Code */
RETURN_CODE); /* Result Code */
}
main()
{
ULONG RamSem = 0L;
ULONG far *RamSemHandle = &RamSem;
USHORT rc;
if(!(rc=DosSetSigHandler((PFNSIGHANDLER) FlagA_Handler,
NULL,
NULL,
SIGA_ACCEPT,
SIG_PFLG_A)))
printf("Main thread has set FlagA handler.\n");
else
/* Error processing on rc */;
if(!(rc=DosSemRequest(RamSemHandle,
TIMEOUT)))
printf("Semaphore obtained.\n");
if(!(DosCreateThread((PFNTHREAD) Thread_A,
&ThreadID,
&ThreadStack[3999])))
printf("ThreadA created.\n");
printf("Main thread will now wait on a Ramsem for a while.\n");
if((rc=DosSemRequest(RamSemHandle,
TIMEOUT))
== ERROR_INTERRUPT)
printf("Main thread interrupted while waiting, rc is %d.\n", rc);
}
Created using Inf-PHP v.2 (c) 2003 Yuri Prokushev
Created using Inf-HTML v.0.9b (c) 1995 Peter Childs