Readme Posted January 28, 2014 Share Posted January 28, 2014 (edited) 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, 2014 by Readme Link to comment
deepzero Posted January 28, 2014 Share Posted January 28, 2014 (edited) 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, 2014 by deepzero 1 Link to comment
Lostin Posted January 29, 2014 Share Posted January 29, 2014 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. 1 Link to comment
Aguila Posted January 29, 2014 Share Posted January 29, 2014 You can try the flag THREAD_PRIORITY_HIGHEST 1 Link to comment
Readme Posted January 29, 2014 Author Share Posted January 29, 2014 seems to work deepzero and aguila. thanks people and lostin, thanks for the suggestion Link to comment
Peter Ferrie Posted January 31, 2014 Share Posted January 31, 2014 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. 1 Link to comment
JMC31337 Posted February 1, 2014 Share Posted February 1, 2014 (edited) 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, 2014 by JMC31337 Link to comment
atom0s Posted February 1, 2014 Share Posted February 1, 2014 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. 1 Link to comment
JMC31337 Posted February 1, 2014 Share Posted February 1, 2014 Thread TSR (under a hung app state)Interesting...Guess that goes for all OS' vista win7 and sp3? Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now