Boost logo

Boost :

Subject: Re: [boost] Subject: Formal Review of Proposed Boost.Process library starts tomorrow
From: Artyom (artyomtnk_at_[hidden])
Date: 2011-02-10 11:11:54


----- Original Message ----
> From: Oliver Kowalke <k-oli_at_[hidden]>
>
> Am 10.02.2011 15:03, schrieb Artyom:
> > Probably it would be ok to provide some parameter
> > on how to wait asynchronously:
> >
> > typedef enum {
> > wait_default, // using thread+waitpid per-process on POSIX OS
> > wait_using_sigaction, // install signal handler
> > wait_using_sigwaitinfo, // install signal handler
> > wait_polling, // poll all waiting pids for end, when
> > // requested - for example by user's signal
> > // handler
> > } wait_method_type;
> >
> >
> >
> > void async_wait(pid ,method_type m = wait_default)
> > #ifdef BOOST_POSIX
> > void poll_handlers(); // check if child completed
> > // called by user when receives sigchld
> > endif
>
> what about this solution (without error handling) on POSIX in one
> special worker-thread:
>
> sigset_t set;
> sigemptyset( & set),
> sigaddset( & set, SIGCHLD); // SIGTERM, SIGINT, SIGQUIT
> pthread_sigmask(SIG_BLOCK, & set, ...);
> int signo( 0);
> sigwait( set, & signo);
> switch ( signo)
> {
> case SIGCHLD:
> while (true)
> {
> int status( 0);
> pid_t child = waitpid(
> -1, % status, WUNTRACED|WCONTINUED);
> if ( -1 == child && ECHILD != child)
> throw runtime_error("waitpid() failed");
> // select data/callabck associated with child
> // from internal storage
> }
> case: ...
> };
>
> Oliver
>

Something like this is fine but and this what I mean
when I had written: wait_using_sigwaitinfo

Small notes:

  1. waitpid should be done for specific pid I waiting for
     to allow other threads to use wait
  2. You need to use WNOHANG so it would not be blocking,
     and allow to check specific ids.
      

So basically such thread need

  forever (
    sigwait(sigchld)
    foreach pid in waiting set
       if(waitpid(pid, WNOHANG) = done)
          notify io_service
          remove pid from waiting set
  }

It may be a single global thread that handles
or some kind of singletone thread that exits if # io_service > 0

Of course user should still be aware of fact that it can't
just do what he wants with SIGCHLD

Artyom

      


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk