Neat idea, Magmai. So I create two threads and a semaphore (initialized to 0) initially, and the threads sleep until the semaphore is above 0, and then they decrement it and do their calculations. So when it's time for the calculations, the main thread just sets the semaphore to 2 and waits for it to be 0 again. That makes alot of sense.
EDIT: I started to code this, but I am confused on how to implement it in Windows. On initialization, I create the two threads, and I call:
ThreadSignal = CreateSemaphore( NULL, 0, 2, NULL );
So that creates a semaphore with an initial value of 0 (and max of 2). The body of the thread function looks like this:
while( 1 ){ WaitForSingleObject( ThreadSignal, INFINITE );// Do AI}
So that should wait for ThreadSignal to be greater than zero, then decrement it and proceed with the AI. The main thread does this when it's time to run the AI:
ReleaseSemaphore( ThreadSignal, 2, NULL );
Setting the semaphore to 2, thus allowing the threads to run. But my problem is the main thread needs to wait for the semaphore to be 0, and I don't know how to do that. Also, it seems like it could be theoretically possible for a single thread to decrement the semaphore twice before the other thread ever gets a chance to look at it. So I don't know how the semaphore code is supposed to work.
Drew_Benton: I do not, but it's worrying that you're having problems... all statistics are reported correctly for me. I assume you downloaded it after I made my lastest post? Oh, also it would be useful to know what OS you're using.
[Edited by - CGameProgrammer on December 17, 2004 3:52:31 AM]