Quote:Original post by wendigo23
I don't know how your code is supposed to behave, but this bit is suspect (kbhit and comments removed for clarity):
*** Source Snippet Removed ***
Should it be set or reset? It can't be both.
The idea is that the code inbetween has to be longer than the WaitForSingleObject() in the ThreadedExecutor. That way there can't be any unwanted prestarts, before the end of the current frame. The last handle(handle[3]) is a block used to ensure that the threads don't continue until the main thread has started again.
Let me restate my logic:
When considering my main thread - The first thing is I wait for the threads to finish processing. When the if statement gets a true, I reset the event that indicates that the main thread is finished. This imples that the main thread is going to work.
The second event I SET, is the event telling my threads that they can start working.
Then my main thread should do some work (and _kbhit) and then reset the event letting my threads know they shouldn't continue working after I set the last event, which tells my thread that the frame is done.
When considering the ThreadedExecutioner:
The if is only there to test if the thread should close and is not used for syncing.
Then the event is set telling the main thread that this one is ready. Then it waits for the main thread to acknowledge (handles[2] in the main thread).
Then the event is reset, indicating that the thread is going to work now.
Then the thread works and waits for the final sync event (handels[3] in main thread.