[m-dev.] Re: warning in timeout.m

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Jun 5 21:11:24 AEST 2001

On 05-Jun-2001, Zoltan Somogyi <zs at cs.mu.OZ.AU> wrote:
> On 04-Jun-2001, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> > timeout.m: In function `timeout_module0':
> > timeout.m:94: warning: implicit declaration of function `alarm'
> alarm is declared in unistd.h.
> Is there an alternative that doesn't rely on unistd.h?

I don't know of any simple, easy alternative.
AFAIK there's no alternative that relies only on ANSI/ISO C.

This is only one place that relies on Posix features; there are a few
others in the deep profiler, e.g. you use named pipes and (in server.m)
unistd.h and fork().  Even if there was a direct Windows equivalent
to alarm(), using Windows-specific functions here isn't going to help
portability (in the general sense) much.

You could use sockets and select() with a timeout;
Win32 does support sockets, last time I looked.
But that's not the right solution for .NET, which uses different APIs;
for .NET there is a Timer class whose constructor takes a delegate as
parameter and calls it (in a separate thread) when the timeout occurs.

Unless you're actually planning to port the deep profiler to Windows,
and thus to address the other portability issues, I'd suggest just using
alarm() and unistd.h.  But there should be an autoconf configure option to
enable/disable the deep profiler support, and on systems where it is not
supported it should be disabled by default.  

Another alternative would be to just make sure that it compiled on
systems that don't have unistd.h, alarm(), or fork(), and have it just
report an error at runtime on those systems, e.g. using autoconf tests
for those functions:

	#ifdef MR_HAVE_FORK
		... code using fork() ...
		MR_fatal_error("... error message ...");

But I think using a `--enable-deep-prof' configure option would be nicer.

Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au

More information about the developers mailing list