Stopping multiple threads.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Poornima_Kini
Posted On:   Thursday, January 31, 2002 09:13 PM

Hi, I have two threads which I invoke from the main. Both of these listen for data on particular ports. Thread1 processes the data, and Thread2 listens for a "Stop message". When this message is received it is supposed to stop itself as well as the other Thread1 and exit from main. Currently I am invoking both the threads from main, and then calling a join on both the threads. How do I signal the Thread1 from Thread2 when it receives a Stop message to exit, so that the control comes to the main, and then I can exit gracefully. Thanks in advance. Regards, Poornima.    More>>


Hi,


I have two threads which I invoke from the main. Both of these listen for
data on particular ports. Thread1 processes the data, and Thread2 listens for a
"Stop message". When this message is received it is supposed to stop itself as
well as the other Thread1 and exit from main.


Currently I am invoking both the threads from main, and then calling a join
on both the threads. How do I signal the Thread1 from Thread2 when it receives a
Stop message to exit, so that the control comes to the main, and then I can exit
gracefully.


Thanks in advance.


Regards, Poornima.

   <<Less

Re: Stopping multiple threads.

Posted By:   Duncan_Forster  
Posted On:   Friday, February 1, 2002 04:13 AM

Overide the

public void stop()
{
stop = true; // boolean value
}
method like this. When your reader loops trying to read data check this flag and exit if true. If the reader is currently blocked waiting for data just close the socket and the reader will throw an exception. It will then check this flag and then exit. To be safe you should have another flag to indicate whether the shutdown was successfull.
About | Sitemap | Contact