public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libfortran/48587] New: Avoid exhausting unit number with NEWUNIT=
@ 2011-04-13  7:40 jb at gcc dot gnu.org
  2011-04-13 10:20 ` [Bug libfortran/48587] " burnus at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: jb at gcc dot gnu.org @ 2011-04-13  7:40 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48587

           Summary: Avoid exhausting unit number with NEWUNIT=
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: libfortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: jb@gcc.gnu.org


As was recently pointed out by Tobias Burnus in a thread on comp.lang.fortran,
the current implementation of NEWUNIT= doesn't reuse unit numbers. Hence it's
possible that a program might exhaust the available unit numbers (this requires
that the program repeatedly closes and reopens files, as OS's have limits on
the number of file descriptors a process may have concurrently opened,
typically 1024 or something like that)

Currently there is just a (mutex protected) static variable which is
decremented for each time an OPEN statement with NEWUNIT= is issued, with a
wraparound check that generates an error if wraparound is detected.

IMHO an elegant solution would be to just reuse the kernel provided file
descriptor. E.g. 

int fd = open(...);
if (fd == -1)
{
    /* Handle error... */
}
new_unit_number = -fd;

This should work because a successful open() will always return a positive fd
number (see
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html ), and
the kernel takes care of reusing file descriptor numbers of closed files.


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-03-03 22:19 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-13  7:40 [Bug libfortran/48587] New: Avoid exhausting unit number with NEWUNIT= jb at gcc dot gnu.org
2011-04-13 10:20 ` [Bug libfortran/48587] " burnus at gcc dot gnu.org
2011-04-13 10:47 ` jb at gcc dot gnu.org
2011-04-13 18:59 ` jvdelisle at gcc dot gnu.org
2011-04-14  8:12 ` jb at gcc dot gnu.org
2011-04-15  9:13 ` jb at gcc dot gnu.org
2011-04-19 13:41 ` fxcoudert at gcc dot gnu.org
2014-03-03 22:19 ` jb at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).