It's been a while since I dealt with unix signals; but in the work I did, the common trick was to disable signals on all threads except one. Then, you only have to deal with handling signals there. Otherwise, you've pretty much always got trouble because you never know which threads will service a signal. Does this work? My memory is hazy because it has been too long :-)
Mike On Fri, May 1, 2009 at 12:35 PM, Adam Langley <a...@chromium.org> wrote: > > On POSIX systems, system calls can be interrupted by signals. In this case, > they'll return EINTR, indicating that the system call needs to be > restarted. > > (The situation is a little more complicated than this with SA_RESTART, but > you > can read man 7 signal if you like.) > > The short of it is that you need to catch EINTR and restart the call for > these > system calls: > > * read, readv, write, writev, ioctl > * open() when dealing with a fifo > * wait* > * Anything socket based (send*, recv*, connect, accept etc) > * flock and lock control with fcntl > * mq_ functions which can block > * futex > * sem_wait (and timed wait) > * pause, sigsuspend, sigtimedwait, sigwaitinfo > * poll, epoll_wait, select and 'p' versions of the same > * msgrcv, msgsnd, semop, semtimedop > * close (although, on Linux, EINTR won't happen here) > * any sleep functions (careful, you need to handle this are restart with > different arguments) > > We've been a little sloppy with this until now. Once the tree reopens, > I'll be > landing 100225 which adds a macro for dealing with this and corrects every > case > of these system calls (that I found). > > The macro is HANDLE_EINTR in base/eintr_wrapper.h. It's safe to include on > Windows and is a no-op there. > > On POSIX, it uses GCC magic to return the correct type based on the > expression > and restarts the system call if it throws EINTR. Here it is: > > #define HANDLE_EINTR(x) ({ \ > typeof(x) ret; \ > do { \ > ret = x; \ > } while (ret == -1 && errno == EINTR); \ > ret;\ > }) > > And you can use it like: > HANDLE_EINTR(close(fd)); > > Or: > ssize_t bytes_read = HANDLE_EINTR(read(fd, buffer, len)); > > > > AGL > > > > --~--~---------~--~----~------------~-------~--~----~ Chromium Developers mailing list: chromium-dev@googlegroups.com View archives, change email options, or unsubscribe: http://groups.google.com/group/chromium-dev -~----------~----~----~----~------~----~------~--~---