views:

89

answers:

1

Is there a semaphone that works like a Chess timer, meaning;

Thread A completes its task, loops back up to the top and calls the Semaphore

This triggers Thread 2 which proceeds through its code, loops back up to the top and calls the Semaphore

This triggers Thread A which...

So the Semaphore is both blocking and signaling.

I know I can just use two events and WaitForSingleObject, but I wondered if there is a semaphore that does this specifically?

While on the subject, how "expensive" is an Event, and how "expensive" is WaitForSingleObject() in terms of memory and CPU?

+4  A: 

Hmmm... Are you sure you need two threads at all? It sounds like your co-routines cannot run concurrently, at least if i'm understanding the metaphore. If that's the case, put them in the same thread.

while (true)
{
    task1();
    task2();
}
TokenMacGuy
Without going into a long winded explanation, they CANNOT run concurrently.
Mike Trader
then you don't need two threads. Period.
TokenMacGuy