What Qmail did was basically to use a named pipe as a trigger,What drains the fifo?
where one program select()s on the FIFO file descriptor, waiting
for another program to write() the FIFO. Once select() returns,
the listener close()s the FIFO (the data was not important,
it was only used as a signal), does some work, then re-open()s
the FIFO file, and ends up in the same select() waiting for the
whole thing to happen again.
for (;;) {xxx now a thread switch
while ((fd = open("test.fifo", O_WRONLY | O_NONBLOCK)) < 0)
;
gettimeofday(&tv1, NULL);
if (write(fd, &fd, 1) == 1) {
gettimeofday(&tv2, NULL);If a thread switch happens in the indicated line, then the reader will loop, until it's timeslice expires - one full timeslice delay between the two gettimeofday() calls.
fprintf(stderr, "dt = %f ms\n",
(tv2.tv_sec - tv1.tv_sec) * 1000.0 +
(tv2.tv_usec - tv1.tv_usec) / 1000.0);
}
if (close(fd) < 0) {
perror("close");