Boost logo

Boost :

From: Aristid Breitkreuz (aribrei_at_[hidden])
Date: 2006-05-09 17:30:54

Am Dienstag, den 09.05.2006, 16:39 -0400 schrieb Stefan Seefeld:
> Aristid Breitkreuz wrote:
> > Am Dienstag, den 09.05.2006, 19:22 +0000 schrieb Ryan Gallagher:
> >> Gennadiy Rozental wrote:
> >>> SIGNAL catching is optional and doesn't constitute portabiltiy issues per se,
> >>> whether to use it's up to you.
> >> Out of curiousity, what is a good (portable?) way of dealing with signals in
> >> C++? C signal handling seems to force globals on you, which is a pain
> >> especially when signal handling is a late requirement.
> >
> > You might want to use a UNIX pipe for that (by calling pipe(2)). Just
> > write(2) into a pipe (less than PIPE_BUF bytes) and select(2) on it.
> > This is thread-safe and signal-safe and everything. Just not too speedy.
> I think semaphores are a widespread way to communicate from signal handlers
> back to a running program. They are reentrant, and their use involves less
> system calls than pipes, I believe.

The huge advantage of pipes is that with select, you can poll multiple
event sources at once. Multiple sem_wait must be placed into multiple
threads, which is probably more overkill for those rare signals than the
selfpipe-trick (as they call it).

> I don't think thinking of portable signal handling mechanisms is sensible,
> as signals themselves are (mostly) non-portable.

In itself, such a mechanism is not too sensible.

> Regards,
> Stefan
> _______________________________________________
> Unsubscribe & other changes:

Boost list run by bdawes at, gregod at, cpdaniel at, john at