August 01, 2001
A Device Driver for W2K Signals
August 2001/A Device Driver for W2K Signals/Listing 2
#define STRICT 1
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "..\dll\signals.h"
/* Global variables to avoid any optimization by the compiler */
long sum1 = 0, sum2 = 0;
volatile unsigned long WaitFlag = 0;
VOID __stdcall fSignal0(VOID)
{
printf("Thread (%ld):Inside the handler \
of signal SIGNAL0!!!\n", GetCurrentThreadId());
return;
}
DWORD WINAPI ThreadRoutine(LPVOID Param)
{
long i;
/* Set a hanndler for SIGNAL0 */
SetSignalHandler(SIGNAL0, fSignal0);
/* Do some stuff.... */
for (i = 0; i < 10000000; i++) sum1++;
/* Wait until the main thread sets the flag */
while (WaitFlag == 0);
return 0;
}
HANDLE hThread;
DWORD ThreadId;
int main()
{
ULONG i = 0;
DWORD Data = 1; /* Not actually used */
/* Create the target thread */
hThread = CreateThread(NULL,0,ThreadRoutine,&Data,0,&ThreadId);
/* Let the target thread to run for a while */
Sleep(1000);
/* Send a signal to the target thread */
printf("Thread (%ld): Sends a signal to the \
target thread\n", GetCurrentThreadId());
SendSignalToThread(hThread, SIGNAL0);
/* Do some stuff and wait for a while */
for (i = 0; i < 10000000; i++) sum2++;
Sleep(1000);
/* Set the flag. The handler must have been executed by now */
WaitFlag = 1;
/* Wait for the thread's termination */
WaitForSingleObject(hThread, INFINITE);
return 0;
}
/* End of File */
Previous Page |
1
|
2
|
3
|
4
|
5
Next Page