How to initialize a KWAIT_BLOCK array

I need to use KeWaitForMultipleObjects to wait on more than
THREAD_WAIT_OBJECTS (i.e. 3). Can someone explain how to setup and use
WAIT_BLOCKs in the call?

Thanks
Jeff


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

NTSTATUS Status;
PKWAIT_BLOCK WaitBlock;
PVOID *ObjectTable;
KSEMAPHORE aSemaphore;
KEVENT aEvent;
ULONG Count=2;

KeInitializeSemaphore(&aSemaphore,0,MAXLONG);
KeInitializeEvent (&aEvent,SynchronizationEvent,FALSE);

WaitBlock = ExAllocatePool( NonPagedPool,
MAXIMUM_WAIT_OBJECTS*sizeof(KWAIT_BLOCK));
if ( WaitBlock ) {
RtlZeroMemory( WaitBlock, MAXIMUM_WAIT_OBJECTS*sizeof(KWAIT_BLOCK));
ObjectTable = ExAllocatePool( NonPagedPool,
MAXIMUM_WAIT_OBJECTS*sizeof(PVOID));
if ( ObjectTable ) {
RtlZeroMemory( ObjectTable, MAXIMUM_WAIT_OBJECTS*sizeof(PVOID));

ObjectTable[0] = &aSemaphore;
ObjectTable[1] = &aEvent;

// we will wait in kernel mode since the objects are on the stack
ASSERT(Count<maximum_wait_objects> Status = KeWaitForMultipleObjects(
Count, //IN ULONG Count,
ObjectTable, //IN PVOID Object,
WaitAny, //IN WAIT_TYPE WaitType,
Executive, //IN KWAIT_REASON WaitReason,
(KPROCESSOR_MODE)KernelMode, //IN KPROCESSOR_MODE WaitMode,
FALSE, //IN BOOLEAN Alertable,
NULL, //IN PLARGE_INTEGER Timeout OPTIONAL,
WaitBlock //IN PKWAIT_BLOCK WaitBlockArray OPTIONAL
);
ExFreePool(ObjectTable);
}
ExFreePool(WaitBlock);
}

rob

> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com]On Behalf Of
> xxxxx@pinnaclesys.com
> Sent: Friday, March 02, 2001 3:46 PM
> To: NT Developers Interest List
> Subject: [ntdev] How to initialize a KWAIT_BLOCK array
>
>
> I need to use KeWaitForMultipleObjects to wait on more than
> THREAD_WAIT_OBJECTS (i.e. 3). Can someone explain how to setup and use
> WAIT_BLOCKs in the call?
>
> Thanks
> Jeff
>
> —
> You are currently subscribed to ntdev as: xxxxx@cdp.com
> To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com</maximum_wait_objects>

In case Rob’s code sample wasn’t clear enough, the caller’s responsibility
is to supply the storage for the wait block array, not to set the array
elements to some initial state. Rob cleared the array to zero, but I think
that is not required (although it can’t hurt and is in general good
practice.)

I’d say that the lack of specificity in the DDK on this issue qualifies as a
DDK Bug, eh? I sure remember having to puzzle over this issue for several
trial and error iterations.

Mark Roddy
Windows 2000/NT Consultant
Hollis Technology Solutions
xxxxx@hollistech.com
603 321 1032
www.hollistech.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com