flat assembler
Message board for the users of flat assembler.
Index
> Windows > How to stop infinite looping thread? |
Author |
|
Akujin 18 Oct 2011, 20:46
Maybe...
Code: hThread dd ? threadID dd ? invoke CreateThread(...thread1..,threadID) mov [hThread],eax invoke Sleep,5000 invoke TerminateThread,[hThread],0 ret .. proc thread1 @@: do something jmp @b ret endp _________________ CLI HLT |
|||
18 Oct 2011, 20:46 |
|
Overflowz 18 Oct 2011, 22:00
Oh! then what this does ?!
lpThreadId [out, optional] A pointer to a variable that receives the thread identifier. If this parameter is NULL, the thread identifier is not returned. what's difference between them ? can anyone explain ? |
|||
18 Oct 2011, 22:00 |
|
Akujin 18 Oct 2011, 22:33
"Until the thread terminates, the thread identifier uniquely identifies the thread throughout the system."
|
|||
18 Oct 2011, 22:33 |
|
ouadji 19 Oct 2011, 00:34
shut down the power supply ? (I tried, it works) a hammer blow on the processor, it works too. |
|||
19 Oct 2011, 00:34 |
|
AsmGuru62 19 Oct 2011, 14:16
The proper way to do it is to have the thread do some work and then check the global variable which will be 1 to continue looping and 0 to stop looping.
The proper way to stop thread is set the variable to 0 and let thread to RETURN from its THREAD PROCEDURE. Using TerminateThread may cause instability in KERNEL32.DLL - depending of what thread will be doing. The variable must be 32-bit in size and must be aligned on 4 byte boundary to allow for atomic read/write operations. |
|||
19 Oct 2011, 14:16 |
|
cod3b453 20 Oct 2011, 17:21
Use WaitMessage or one of the xxxWaitForxxx API to pause the thread. In the message case you can use Peek/GetMessage to read the message and choose what to do. Messages can be sent to the thread using PostThreadMessage.
|
|||
20 Oct 2011, 17:21 |
|
f0dder 20 Oct 2011, 17:36
Overflowz wrote: Oh! then what this does ?! And, as others have suggested, TerminateThread isn't good and should only be used as a last resort. _________________ - carpe noctem |
|||
20 Oct 2011, 17:36 |
|
Overflowz 20 Oct 2011, 21:01
Thank you everyone, I understand it now.
|
|||
20 Oct 2011, 21:01 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.