Page 1 of 1

ISemaphore missing in action

PostPosted: Tue Jul 01, 2008 6:19 am
by David Gottschalk
Hello,

I want to convert some existing code to using the madKernel interfaces. In one place I use WaitForMultipleObjects to wait on a semaphore and an event. I was thinking I would use

function WaitFor (const objects : array of IBasic;
waitAll : boolean = false;
milliseconds : cardinal = INFINITE;
handleMessages : boolean = true;
msgs : TWaitForMessages = [];
alertable : boolean = false ) : integer; overload;

but it seems there is no ISemaphore.

Is there a reason to not have an ISemaphore?

Should I still use WaitForMultipleObjects and feed in the handle from the IEvent?

thanks

PostPosted: Thu Jul 03, 2008 9:41 pm
by madshi
You're right that there's no ISemaphore. Maybe I should add that. Anyway, you could use "yourSemaphore := madKernel.Handle(yourSemaphoreHandle, false)" to convert your manually created semaphore handle into a madKernel compatible "IHandle" instance. After having done that you can use "WaitFor([yourEvent, yourSemaphore])". Of course you can also use WaitForMultipleObjects and feed in "yourEvent.Handle.Handle" (the first "Handle" returns an IHandle instance, then calling "IHandle.Handle" finally returns a standard win32 handle dword for use with WaitForMultipleObjects).

PostPosted: Sun Jul 06, 2008 11:49 pm
by David Gottschalk
Hello,

I will convert it to an IHandle instance as the other way reduces the advantages of using your code. If you do create an ISemaphore I will switch to using that.

thanks