Re: [linux-audio-dev] the alternate API for LAAGA: its problems

New Message Reply About this list Date view Thread view Subject view Author view Other groups

Subject: Re: [linux-audio-dev] the alternate API for LAAGA: its problems
From: Paul Davis (pbd_AT_Op.Net)
Date: Thu Jul 05 2001 - 14:51:10 EEST


>Why not using a signal ? This signal would interrupt the select(), making
>it return with errno==EINTR. You can then retry the select() after getting
>the new file descriptor. This preserves also the select/poll returning
>an error for true engine errors, such as engine crash.
>
>The problem is that this leaves some code to be handled by the application
>code and not the library, as in:
>
>if (select(n,&rfds,&wfds,&efds,0) < 0) {
> if (errno == EINTR)
> laaga_fd = laaga_get_process_start_fd();
> else
> exit(1);
>}

The difficulty with that approach is that there are other reasons why
we might have been interrupted. In particular, I have found that
looping on EINTR can be very dangerous in threaded programs because
they seem to be able to avoid exiting ...

However, I suppose with a little work:

   int the_fd_changed;
         
   signal (SIGWHATEVER, fd_changed); // more likely sigaction
                                        to allow proper semantic control
   
   void fd_changed (int sig)
   {
        the_fd_changed = TRUE;
   }

   the_fd_changed = FALSE;
   if (select(n,&rfds,&wfds,&efds,0) < 0) {
        if (errno == EINTR && the_fd_changed)
                laaga_fd = laaga_get_process_start_fd();
        else
                exit(1);
   }

This still looks a bit ugly, but it would work OK. There is another
problem too: you have to keep track of the thread ID of the thread
that will be doing select/poll (so you call pthread_kill() it). The
docs for the function would have to make clear that it must be called
only from the thread that will use it in this way.

--p


New Message Reply About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b28 : Thu Jul 05 2001 - 14:51:55 EEST