help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem with parallel make


From: David Boyce
Subject: Re: Problem with parallel make
Date: Sun, 30 Jul 2006 10:34:02 -0400

At 10:02 AM 7/30/2006, Paul D. Smith wrote:
%% Lee Killough <address@hidden> writes:
  lk> Perhaps a larger filehandle number, less likely to occur in common
  lk> shell redirection idioms, should be used for the jobserver.

Well, pipe(2) doesn't allow you to choose your own file descriptors: it
just uses the lowest available descriptors.  I could use dup2(2) to
force different ones after the pipe has been created, but there's no
portable way in POSIX (that I know of) to find the maximum valid file
descriptor.  I guess we could just use OPEN_MAX, if we can figure it
out.

I have something like this in my code. What I chose to do, rather than try to determine the max fd, was to pick a number north of (say) 50 and south of 256. I try to dup to that and then, if it fails, the next 10 values or so (or I guess you could go to 257 or 1025 if so inclined). If none of them works, I just drop back to using what the OS gave me. ISTM the odds of of this not working are very low and even if it doesn't you're no worse off.

Here's the relevant code (seeing it again for the first time in a while, I think the lseek is redundant).

        #define PREFERRED_FD            180

        // If our preferred fd is not in use, try using it.
        // Try a few above that also.
        for (fd = -1, i = 0; i < 10; i++) {
            if (lseek(PREFERRED_FD + i, 0, SEEK_CUR) == -1) {
                if (dup2(fileno(tfp), PREFERRED_FD + i) != -1) {
                    fd = PREFERRED_FD + i;
                    break;
                }
            }
        }

        // If all the above efforts failed, just ask the system
        // for the next available descriptor.
        if (fd == -1) {
            if ((fd = dup(fileno(tfp))) == -1)
                syserr(2, "dup");
        }

-David Boyce






reply via email to

[Prev in Thread] Current Thread [Next in Thread]