How to stop a thread from another thread.
-
Hi, I created a thread using the AfxBeginthread function. How do I stop this thread from another thread. MSDN resources say that its dangerous to use call TerminateThread. I tried using it too, but it failed to terminate it. Thanks, Deepak Samuel.
-
Hi, I created a thread using the AfxBeginthread function. How do I stop this thread from another thread. MSDN resources say that its dangerous to use call TerminateThread. I tried using it too, but it failed to terminate it. Thanks, Deepak Samuel.
one way is to set a global boolean flag like g_fExit = true, from whichever thread you want ..so that the corresponding thread sees that and return.
It's not a bug, it's an undocumented feature.
suhredayan@omniquad.commessenger :suhredayan@hotmail.com
-
Hi, I created a thread using the AfxBeginthread function. How do I stop this thread from another thread. MSDN resources say that its dangerous to use call TerminateThread. I tried using it too, but it failed to terminate it. Thanks, Deepak Samuel.
Check the CEvent for MFC or the events in general for WIN32 The main idea: in the loop of the thread that you want to stop, call WaitForSingleObject with WAIT_OBJECT_0 on the event handle, and in case it is signaled you just have to return :) and in the other thread just signal the event Papa while (TRUE) Papa.WillLove ( Bebe ) ;
-
one way is to set a global boolean flag like g_fExit = true, from whichever thread you want ..so that the corresponding thread sees that and return.
It's not a bug, it's an undocumented feature.
suhredayan@omniquad.commessenger :suhredayan@hotmail.com
-
Check the CEvent for MFC or the events in general for WIN32 The main idea: in the loop of the thread that you want to stop, call WaitForSingleObject with WAIT_OBJECT_0 on the event handle, and in case it is signaled you just have to return :) and in the other thread just signal the event Papa while (TRUE) Papa.WillLove ( Bebe ) ;
i told that was one way and perhaps the simplest. see wot Jeffery Ricther has to say. [^] "its easy to make complex and complex to make simple" :)
It's not a bug, it's an undocumented feature.
suhredayan@omniquad.commessenger :suhredayan@hotmail.com
-
i told that was one way and perhaps the simplest. see wot Jeffery Ricther has to say. [^] "its easy to make complex and complex to make simple" :)
It's not a bug, it's an undocumented feature.
suhredayan@omniquad.commessenger :suhredayan@hotmail.com
Both are easy and simple to use, but i would rather go with events as it sure that it would be thread safe.
God is Real, unless declared Integer.
-
i told that was one way and perhaps the simplest. see wot Jeffery Ricther has to say. [^] "its easy to make complex and complex to make simple" :)
It's not a bug, it's an undocumented feature.
suhredayan@omniquad.commessenger :suhredayan@hotmail.com
suhredayan® wrote: see wot Jeffery Ricther has to say. either Jeffery is ur pal ,or you been eating pages of his book.:laugh:
God is Real, unless declared Integer.
-
Both are easy and simple to use, but i would rather go with events as it sure that it would be thread safe.
God is Real, unless declared Integer.
sounds nice.. please explain the need for thread saftey for this line: g_fExit = true :confused: that also with the help of an MFC object !
It's not a bug, it's an undocumented feature.
suhredayan@omniquad.commessenger :suhredayan@hotmail.com
-
suhredayan® wrote: see wot Jeffery Ricther has to say. either Jeffery is ur pal ,or you been eating pages of his book.:laugh:
God is Real, unless declared Integer.
maatha>pitha>guru>god btw not a pal, but > god thats wot i have learnt.
It's not a bug, it's an undocumented feature.
suhredayan@omniquad.commessenger :suhredayan@hotmail.com
-
sounds nice.. please explain the need for thread saftey for this line: g_fExit = true :confused: that also with the help of an MFC object !
It's not a bug, it's an undocumented feature.
suhredayan@omniquad.commessenger :suhredayan@hotmail.com
No, i am not tring to be within the context on this problem only... In general senario where threads need to be syncronised i would use kernel objects rather than some variables.;)
God is Real, unless declared Integer.
-
Hi, I created a thread using the AfxBeginthread function. How do I stop this thread from another thread. MSDN resources say that its dangerous to use call TerminateThread. I tried using it too, but it failed to terminate it. Thanks, Deepak Samuel.
PostThreadMessage(ThreadId, WM_QUIT, 0, 0);
-
No, i am not tring to be within the context on this problem only... In general senario where threads need to be syncronised i would use kernel objects rather than some variables.;)
God is Real, unless declared Integer.
it 'd 'nt be fair if i dont mention the risk of deadlock. For any big and complex program it 'd be programmers nightmare to maintain all those handles. if he has lot of threads and want to stop them form others. seems you didnt faced any such problem yet.
It's not a bug, it's an undocumented feature.
suhredayan@omniquad.commessenger :suhredayan@hotmail.com
-
it 'd 'nt be fair if i dont mention the risk of deadlock. For any big and complex program it 'd be programmers nightmare to maintain all those handles. if he has lot of threads and want to stop them form others. seems you didnt faced any such problem yet.
It's not a bug, it's an undocumented feature.
suhredayan@omniquad.commessenger :suhredayan@hotmail.com
suhredayan® wrote: if he has lot of threads and want to stop them form others thats what kernel object are for, using it efficiently gives good results.
God is Real, unless declared Integer.
-
suhredayan® wrote: if he has lot of threads and want to stop them form others thats what kernel object are for, using it efficiently gives good results.
God is Real, unless declared Integer.
i would be greatful if you explain the pitfall in following line if executed from multiple thread. g_fExitThread=true; or atleast the need from the kernal resource, to do the above.
It's not a bug, it's an undocumented feature.
suhredayan@omniquad.commessenger :suhredayan@hotmail.com
-
PostThreadMessage(ThreadId, WM_QUIT, 0, 0);
The problem with using PostThreadMessage or SendNotifyMessage is that worker threads typically don't have message loops, so these functions are not helpful always.
It's not a bug, it's an undocumented feature.
suhredayan@omniquad.commessenger :suhredayan@hotmail.com
-
i would be greatful if you explain the pitfall in following line if executed from multiple thread. g_fExitThread=true; or atleast the need from the kernal resource, to do the above.
It's not a bug, it's an undocumented feature.
suhredayan@omniquad.commessenger :suhredayan@hotmail.com