[Spread-users] Question about thread-safety

James Rauser j.rauser at science-factory.com
Mon Jun 16 03:24:08 EDT 2003


John Schultz wrote:
> 
> NOTE: if anyone knows how to instruct Unix/Linux systems not to reuse
> file descriptor IDs in a process, could you please email me or the list
> a good reference (with page #)? Thanks!

I can vouch for the fact that this is a problem; in my context it was
occuring in a server which forked child processes to handle requests.
The children each called close() on the inherited spread mailbox,
then reestablished their own connection with SP_connect().   The children
can't call SP_disconnect(), because we don't really want to disconnect
it.  But: the child's copy of spread's internal session table wasn't
updated, so if the new SP_connect() call obtained the same numerical
FD, the library got confused.

I solved it by dup()ing the inherited FD onto an open file descriptor
for /dev/null and just leaving it open.  Instead of:

   close(mSpreadMbox)

I use:

   int tempfd = ::open("/dev/null", O_RDONLY);
   dup2(tempfd, mSpreadMbox);   // now mSpreadMbox is a handle to /dev/null
   ::close(tempfd);

which wastes one open FD per child process.  I don't think there's any
standard way to force the kernel to never re-use a file descriptor
without leaving it open as e.g. above.  Even if there was, a
long-running, multithreaded  process would eventually run out of
file descriptors.

Greetings,
Jim

-- 
------------------------------------------------------------------------
Jim Rauser                                          Science Factory GmbH
mailto:j.rauser at science-factory.com                       Unter Käster 1
Tel: +49 221 277 399 204                          50667 Cologne, Germany




More information about the Spread-users mailing list