Daniel Koch
11/26/2008 7:52:00 PM
On 26 nov, 16:24, James Kanze <james.ka...@gmail.com> wrote:
> On Nov 26, 6:01 pm, Daniel Koch <daniel.k...@gmail.com> wrote:
>
> > I've a doubt about POSIX C functions when I'm using with C++.
> > I need to handle a signal, the signal() from signal.h needs a
> > callback. This callback need to perform an action inside
> > class.
>
> You can't do that from a signal handler, at least not reliably.
>
> > How can I define this callback as my instance method?
>
> You can't.
>
> > I think the wrong way is to define a pointer to class instance
> > (this) as global, then I can call public methods of class from
> > this callback (the callback defined by signal() haven't a void
> > pointer to pass an instance pointer).
>
> Even that's not guaranteed to work. The relevant standards (C,
> C++ and Posix) don't even allow you to read a pointer, much less
> do anything with it.
>
> > What's the right way to do this?
>
> Do what? The usual way of associating complex actions with a
> signal under Posix is to use a signal handling thread, using
> sigaction to block the signals in all of the other threads, and
> sigwait in the signal handling thread. This should all be
> described in your books on Unix programming (and since it is so
> Unix specific, if you have further questions, you should ask in
> a Unix group).
>
> --
> James Kanze (GABI Software) email:james.ka...@gmail.com
> Conseils en informatique orientée objet/
> Beratung in objektorientierter Datenverarbeitung
> 9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
I've found Glib::SignalChildWatch.
I'm using gtkmm to show some windows and it is using libsigc++,
now I can use an instance method as signal handlers. :)
Thank you.
Daniel Koch