Posted January 28, 201411 yr i created a thread using CreateThread succesfully. the problem is that the thread is not directly after creating is executed.the thread will be executed after calling Sleep().the thread is not created in suspended mode, but with the creation flag 0 (0 = The thread runs immediately after creation.). but still the thread is not executed direclty. any suggestions? invoke CreateThread, 0, 0, addr ThreadProc, NULL, 0, addr dwThreadID invoke Sleep, 200 ; when reaching this code the thread created above should be executed first Edited January 28, 201411 yr by Readme
January 28, 201411 yr there is no guarantee a switch is made right after calling CreateThread. You should call a function like WaitForSingleObject to make that happen. http://msdn.microsoft.com/en-us/library/windows/desktop/ms687032%28v=vs.85%29.aspx Edited January 28, 201411 yr by deepzero
January 29, 201411 yr Alternatively you can use a Boolean global variable and check on a loop from your main thread if its true then execute your code. You set this value to true from your newly created thread. Just a suggestion though.
January 29, 201411 yr Author seems to work deepzero and aguila. thanks people and lostin, thanks for the suggestion
January 31, 201411 yr The whole point of the thread scheduler is that *the scheduler* gets to decide when the thread will execute. Given enough critical-priority threads elsewhere in the system, you can end up with your thread essentially never running at all.
February 1, 201411 yr The whole point of the thread scheduler is that *the scheduler* gets to decide when the thread will execute. Given enough critical-priority threads elsewhere in the system, you can end up with your thread essentially never running at all. is that helpful for the system or can it be exploited? creating a thread and it never running, doesnt a thread die with the program that creates it? Edited February 1, 201411 yr by JMC31337
February 1, 201411 yr is that helpful for the system or can it be exploited? creating a thread and it never running, doesnt a thread die with the program that creates it? Depending on how the application is exited, it is not guaranteed to hault the threads which will leave the application in a 'hung' state while the threads continue to run. As Microsoft explains: The thread object remains in the system until the thread has terminated and all handles to it have been closed through a call to CloseHandle.
February 1, 201411 yr Thread TSR (under a hung app state)Interesting...Guess that goes for all OS' vista win7 and sp3?
Create an account or sign in to comment