starting compile server - advice needed
Daniel Jacobowitz
drow@mvista.com
Fri Jul 11 22:16:00 GMT 2003
On Fri, Jul 11, 2003 at 02:42:24PM -0700, Per Bothner wrote:
> As I've mentioned before, I am working for Apple on a "gcc compile
> server", where cc1/cc1plus/... are started up in server mode, and wait
> on a socket for compilation requests. (The primary goal is compilation
> speed, as the server can remember the declarations etc from previous
> header files.)
>
> At the Gcc Summit in Ottawa I mentioned a problem for which I could use
> some help: How to have a client automatically start up a server if one
> isn't running already.
>
> In the existing code, the server has to be started and stopped manually.
> After it has been started, it creates a Unix domain socket (which is
> bound to ./.cc1-server in the case of cc1), and waits listening for
> compilation requests. A client runs gcc in the normal manner, but if
> the --server option is pased to gcc, then gcc sends compilation requests
> to the server, instead of forking a fresh cc1.
>
> What I would like is for --server to not fail if no server is running,
> but to automatically start a new server and use that. The new server
> would hang around for a while, handling other compilation requests,
> exiting if there is no compilation request within a specified timeout
> (perhaps 10 minutes by default).
>
> So my question is: What is the recommended method for starting a server
> if one isn't running? Note that what makes this non-obvious are various
> race conditions: The client has to wait until the server has started,
> initialized itself, and is ready for a connection. Furthermore, it is
> possible (but less likely) for some other client to have already started
> a server, but we don't see it because isn't yet listening for connections.
It seems to me that the best way to do this would be to have the server
create the something atomically - O_EXCL - and then any client which
saw the socket was missing would start a server. If the atomic create
fails, assume another process is starting the server, exit.
--
Daniel Jacobowitz
MontaVista Software Debian GNU/Linux Developer
More information about the Gcc
mailing list