First a little background:
I am currently working on a program that waits for data from users via the internet.Currently , it immedialtely processes the information using a thread. I am adding a feature that allows the user to process the information at a time delay instead of immediatey. To do this I created a thread that simply sleeps for the length of the time delay, afterwhich the ProcessData thread is started. I used a critical section as a means of synchronizing the threads (this was necessary because if they were not synchronized I got a C++ runtime error).
The problem that I am having now is that the process waits to deal with the data that is being sent by the user until after the delay from a previous user has been completed. I am currently using WaitForMultipleObjects which is leading to the problem. Using WaitForSingleObject(DelayThread,INFINITE) and this leads to the same problem. If I don't have a wait at all I get a C++ runtime error.
Here is my question:
How can I have the program process infromation from one source at a delay and still have it process information from another source that is not at a delay WITHOUT the second set of information having to wait until after the delay thread has been completed for the first set of infromation?
I hope this makes sense.
GetTickCount() is my preference for a quick easy timestamp... yes it's milliseconds since Windows was booted, returned in a DWORD. It's not a good timestamp if you need precision in your delays, the value is in milliseconds but is only updates every 10ms or so, and sometimes falls behind if the system is busy.
DWORD dwNow = GetTickCount();
if (dwNow - timestamp) >= delaytime) etc.
[Note that you shouldn't say if (dwNow <= timestamp+delaytime) because the DWORD overflows every 50 days or so and the comparison will fail... the one I gave you will still work.]
As to which message to send next... if all messages have the same delay, you can just look at the end of the array where the oldest message is and check its timestamp (it's functioning as a queue). If however different message have different delays, you will have to check each entry in the array to find which entries' delay has expired and thus are ready to be processed.