I have an object which does some work in an endless loop. The main()
instantiates the object and calls the run()
method. Since I don\'t want to use thr
There is very little that you can do portably in a signal handler. Basically, you can store a value in an object whose type is sig_atomic_t
. Inserting into cout
, for example, doesn't have to work. If you have C++11 you can do a bit more, using atomic types or explicit fences, but any other calls into the standard library aren't required to do anything sensible.
So, with all that said, what you can do is write a function (either a free function or a static member function (but there is a subtle issue here with C++ linkage: formally a static member function won't work, but in practice it always does)) that calls the member function, which in turn sets running
to false
(assuming you've changed the type of running
to sig_atomic_t
).