Jump to content
Tuts 4 You

thread starting


Readme

Recommended Posts

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 by Readme
Link to comment

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.


  • Like 1
Link to comment

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.

  • Like 1
Link to comment

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 by JMC31337
Link to comment

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.
  • Like 1
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...