By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,906 Members | 1,388 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,906 IT Pros & Developers. It's quick & easy.

Gracefull termination of execution.

P: 1
Hi all,

I have a problem and I wanted to solve it :-).

My problem is I have an application (under GNU/Linux) wich launches a thread, executes some code and collects some statistics. My problem is I want to stop the execution of this code by some sort of key code ( something like Control-C), but I don't want to terminate, instead I want to simply stop the executing thread and perform some calculations with the statistics.
I could do this simply by using signal's but this I'm using C++ and since I'm using exceptions and the class that contains the exceuted code cannot be a singleton I'm in a dilema. I can't figure out a way to stop the execution of this code without terminating the whole program. Below is some pseudo-code trying to better exlpain my problem.


class my_class
{
thread_execution_function();
do_some_statistics();
....
}


my_class::thread_execution_function()
{
while( !terminate)
{
executing....;
}
}


code:

....

my_class.thread_execution_function();

my_class.do_some_statistics();

...

This is basicly my problem. If someone has any idea I would be gratelly appreciated.

Kind Regards.

Josť Rui
May 31 '07 #1
Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,197
Presumable you could signal the thread which would cause it to look in a global area for what to do. Like pause. Or quit.
May 31 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.