Original Post
🔒 Locked
Multithreading question
Advertisement
I don't have an official answer, but I think Sleep is naively implemented based on timestamps:
store_begin_time
while(time_now < (begin_time + length_of_sleep))do_nothing();
If the ResumeThread takes place after the alloted time then the time_now will obviously be after the begin_time + length_of_sleep, so the Sleep will immediately be done.
Edit for pedants: I realize it will be more efficient to store the summed time and compare time_now against that instead of adding in each loop iteration.
[edited by - flangazor on April 27, 2004 9:48:41 AM]
store_begin_time
while(time_now < (begin_time + length_of_sleep))do_nothing();
If the ResumeThread takes place after the alloted time then the time_now will obviously be after the begin_time + length_of_sleep, so the Sleep will immediately be done.
Edit for pedants: I realize it will be more efficient to store the summed time and compare time_now against that instead of adding in each loop iteration.
[edited by - flangazor on April 27, 2004 9:48:41 AM]
I expect it would wake up at the same time as it would anyway, or if it is late already, it would wake up immediately.
In any case, calling SuspendThread is something which should be done with extreme caution. The other thread could have a lock held which may cause total deadlock.
Mark
In any case, calling SuspendThread is something which should be done with extreme caution. The other thread could have a lock held which may cause total deadlock.
Mark
Why to ask if I can test it myself?
So atleast on windows xp the sleep is ended when SuspendThread is called and it continues immediately after ResumeThread.
Another question:
What's the best way to handle communication between threads?
EasyGL - easy to use graphics library.
[edited by - Atm97fin on April 27, 2004 12:08:08 PM]
So atleast on windows xp the sleep is ended when SuspendThread is called and it continues immediately after ResumeThread.
Another question:
What's the best way to handle communication between threads?
EasyGL - easy to use graphics library.
[edited by - Atm97fin on April 27, 2004 12:08:08 PM]
SuspendThread is a debugging tool, it''s not supposed to be used for production code (unless you''re writing a debugger
), so that''s why I think it violates the Sleep rule (Sleep is supposed to stay asleep for at least x milliseconds, perhaps more, never less).
...
Thread-safe queues for threads, pipes are for inter-process communication.
...
Thread-safe queues for threads, pipes are for inter-process communication.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement