Skip to main content
gamedev.net
🔒 Locked

Multithreading question

Started by Atm97fin Apr 27, 2004 at 7:32 AM 4 replies 450+ views
Original Post
Atm97fin
Atm97fin
In windows if I call Sleep() in a thread and during that the threads motherthread calls SuspendThread(), will that child thread continue the sleep after ResumeThead() is called? EasyGL - easy to use graphics library.
EasyGL - easy to use graphics library.
flangazor
flangazor
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]
markr
markr
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
Atm97fin
Atm97fin
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]
EasyGL - easy to use graphics library.
Shannon Barber
Shannon Barber
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.
The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.