problem in THREAD TERMINATE
-
Hi, All I am Creating a Thread Using CreateThread() Function and in it's procedure I am performing my Task But on a Specific Condition i want Terminate it and for it I am using TerminateThread() Function but it Return 0 Which indicate Failure as per msdn it require that my CreateThread() handle must have THREAD_TERMINATE access How Can i Set it? Thanks Mitesh
~Khatri Mitesh khatrimitesh@hotmail.com Bikaner (Rajasthan) INDIA
-
Hi, All I am Creating a Thread Using CreateThread() Function and in it's procedure I am performing my Task But on a Specific Condition i want Terminate it and for it I am using TerminateThread() Function but it Return 0 Which indicate Failure as per msdn it require that my CreateThread() handle must have THREAD_TERMINATE access How Can i Set it? Thanks Mitesh
~Khatri Mitesh khatrimitesh@hotmail.com Bikaner (Rajasthan) INDIA
~Khatri Mitesh~ wrote:
But on a Specific Condition i want Terminate it and for it I am using TerminateThread() Function
You should never end a thread this way. A much better approach is to simply set a flag that is checked regularly by your thread. When the flag is set, the thread knows it has to end and it will do it naturally (instead of being killed in the middle of something).
Cédric Moonen Software developer
Charting control [v1.5] OpenGL game tutorial in C++ -
Hi, All I am Creating a Thread Using CreateThread() Function and in it's procedure I am performing my Task But on a Specific Condition i want Terminate it and for it I am using TerminateThread() Function but it Return 0 Which indicate Failure as per msdn it require that my CreateThread() handle must have THREAD_TERMINATE access How Can i Set it? Thanks Mitesh
~Khatri Mitesh khatrimitesh@hotmail.com Bikaner (Rajasthan) INDIA
You should never use TerminateThread(), since it can easly cause deadlock in your application. Check this[^] and the documentation from MSDN below. MSDN: TerminateThread is a dangerous function that should only be used in the most extreme cases. You should call TerminateThread only if you know exactly what the target thread is doing, and you control all of the code that the target thread could possibly be running at the time of the termination. For example, TerminateThread can result in the following problems: Well, you could use event object to implement same behavior. Well, in the mean while i found this thread[^] also. May be useful to you. Regards, Jijo.
_____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.
-
Hi, All I am Creating a Thread Using CreateThread() Function and in it's procedure I am performing my Task But on a Specific Condition i want Terminate it and for it I am using TerminateThread() Function but it Return 0 Which indicate Failure as per msdn it require that my CreateThread() handle must have THREAD_TERMINATE access How Can i Set it? Thanks Mitesh
~Khatri Mitesh khatrimitesh@hotmail.com Bikaner (Rajasthan) INDIA
As previous replies stated, you should never call
TerminateThread
(since there are better ways to handle your scenario). Anyway, if you're stuck on your (bad) idea, what about reading the documentation [^]?If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]