mov eax,OFFSET ThreadProc
invoke CreateThread,NULL,NULL,eax,\
invoke CloseHandle,eax

ThreadProc PROC USES ebx Param:DWORD

Bla Bla

ThreadProc endp


Right after my procedure ends is the cpu time slice for the procedure taken away or does it still exist. Also does the CloseHandle function destroy the handle. The thing i am trying to figure out is if i call CreateThread again and again for the same procedure at variouse times in my program...will i be continually increasing the demand on system resources.I'm using global variables in my procedure.

Thanx :confused:
Posted on 2001-09-04 14:30:49 by titan
When the ThreadProc function returns, the thread is stopped.
CloseHandle does not stop the thread, it just frees a little memory.
This memory will be freed when the thread exits as well. But if you
don't use the thread handle, it's "nice" to the system resources if
you CloseHandle on it... dunno how much it matters though.

As for calling CreateThread again and again... well, sure, the more
threads you have running at the same time, the higher the CPU load.

Using global variables in a thread procedure can be really really bad.
You will definitely need to synchronize access to it (EnterCriticalSection).
Unless you *must* use global data, you local... that way it's thread-safe.
Posted on 2001-09-04 14:56:11 by f0dder
It is also safe if you dont use the same global variables in 2 diffrent need for locals ;)

Usage of Local variables is Required ONLY if the same function is called from 2 different Threads

But sooner or later THREADS will have to talk to eachother so at least usage of EnterCriticalSection and LeaveCriticalSection is somehow Mandatory

Also dont forget to define the used CriticalSections BEFORE you use them ;) dont forget windows will call your WinMain Callback when it likes....
Posted on 2001-09-04 16:07:52 by BogdanOntanu
Well, the variables I say you should put LOCAL are obviously variables
that would be logical to have in local scope :). If you have a handle
that is only used in one thread (or is per-thread). Or if you run out
of registers and need a variable to help... that sort of stuff.
This has the benefit of being able to run multiple instances of the
same thread, which can be very handy.

As for critical sections... also remember to initialize them :].
Posted on 2001-09-04 17:10:40 by f0dder