Click to See Complete Forum and Search --> : Locking a thread when is not needed and resume it when is needed.


Alphadan
June 4th, 2011, 06:44 AM
hello i want to pause a thread when is not needed and resume it when i need it latter.

I tried using SuspendThread and ResumeThread but it behaves bugy when try to suspend and resume quickly, i been told that is not a good practice to use those functions if im not developing a debugger.

im not trying to sincronize multiple threads i dont have troubles with that critical sections and mutex works just fine.

i want to lock the thread so i could save system resources and resume when i need it.

i been trying to use WaitForSingleObject but it "Locks" only when another thread obtains the mutex but i want to be able to lock the thread form it self.

something like

while(Lock==true){
Sleep(50);
}

if i set the Lock to false from another thread this thread would resume. and pick another job.

am i able to get this functionality by using WaitForSingleObject?

S_M_A
June 4th, 2011, 07:53 AM
The first thing that comes to my mind is a semaphore http://msdn.microsoft.com/en-us/library/ms682438(VS.85).aspx but on the other hand, why is the thread running if it doesn't have anything to do in the first place?