[m-dev.] sleep

Julien Fischer juliensf at csse.unimelb.edu.au
Mon Mar 2 16:59:28 AEDT 2009


On Mon, 2 Mar 2009, Ben Mellor wrote:

> Hi
>
> Do people think the following would be useful enough to put in the standard
> library?

Not really.  The other problem with calling sleep() is that it is not
available on all systems, e.g. on Windows you need to call Sleep.

> :- impure pred sleep(int::in) is det.
>
> :- pred sleep(int::in, io::di, io::uo) is det.
>
> :- pragma promise_pure(sleep/3).
> sleep(Seconds, !IO) :-
>    impure sleep(Seconds).
>
> :- pragma foreign_proc("C",
>    sleep(Seconds::in),
>    [will_not_call_mercury, thread_safe],
> "
>    sleep(Seconds);
> ").

The body of this foreign_proc would need to be something like;

 	#if defined(MR_HAVE_SLEEP)
 		sleep(Seconds);
 	#elif defined(MR_HAVE_CAPITAL_S_SLEEP)
 		Sleep(Seconds);
 	#else
 		?????
 	#endif

(The MR_* macros above are defined in mercury_conf.h in the runtime.)

Julien.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at csse.unimelb.edu.au
Administrative Queries: owner-mercury-developers at csse.unimelb.edu.au
Subscriptions:          mercury-developers-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the developers mailing list