caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Waiting for float time
@ 2007-06-27 21:55 sayan
  2007-06-27 22:11 ` [Caml-list] " Karl Zilles
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: sayan @ 2007-06-27 21:55 UTC (permalink / raw)
  To: caml-list

Hi,

I am looking for a floating point version of the function Unix.sleep in
order to suspend execution of a program for 0.7s

Is there any such function in the standard library ?

Is there a solution outside of Threads, and GTK ?

I have looked at Unix.interval_timer but I'd rather not use it. From
what I understand, you have to add a signal handler to catch sigalrm,
and I do not see how to create a sleep function using it.

Is there a multiplatform solution ?

Thanks

-- 
Sébastien


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

* Re: [Caml-list] Waiting for float time
  2007-06-27 21:55 Waiting for float time sayan
@ 2007-06-27 22:11 ` Karl Zilles
  2007-06-28 11:15   ` Matthieu Dubuget
  2007-06-27 22:21 ` Robert Roessler
  2007-06-28 12:50 ` Thomas Fischbacher
  2 siblings, 1 reply; 13+ messages in thread
From: Karl Zilles @ 2007-06-27 22:11 UTC (permalink / raw)
  Cc: caml-list

sayan@crans.org wrote:
> I am looking for a floating point version of the function Unix.sleep in
> order to suspend execution of a program for 0.7s

Use select with no file_descrs.


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

* Re: [Caml-list] Waiting for float time
  2007-06-27 21:55 Waiting for float time sayan
  2007-06-27 22:11 ` [Caml-list] " Karl Zilles
@ 2007-06-27 22:21 ` Robert Roessler
  2007-06-28 10:15   ` sayan
  2007-06-28 11:33   ` Yaron Minsky
  2007-06-28 12:50 ` Thomas Fischbacher
  2 siblings, 2 replies; 13+ messages in thread
From: Robert Roessler @ 2007-06-27 22:21 UTC (permalink / raw)
  To: Caml-list

sayan@crans.org wrote:
> I am looking for a floating point version of the function Unix.sleep in
> order to suspend execution of a program for 0.7s
> 
> Is there any such function in the standard library ?
> 
> Is there a solution outside of Threads, and GTK ?
> 
> I have looked at Unix.interval_timer but I'd rather not use it. From
> what I understand, you have to add a signal handler to catch sigalrm,
> and I do not see how to create a sleep function using it.
> 
> Is there a multiplatform solution ?

I believe the OCaml idiom for this is to use Unix.select with empty 
lists for all THREE of the descriptor lists... and this does work on 
Windows.

There may be better solutions... ;)

Robert Roessler
roessler@rftp.com
http://www.rftp.com


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

* Re: [Caml-list] Waiting for float time
  2007-06-27 22:21 ` Robert Roessler
@ 2007-06-28 10:15   ` sayan
  2007-06-28 10:18     ` Vincent Hanquez
  2007-06-28 11:33   ` Yaron Minsky
  1 sibling, 1 reply; 13+ messages in thread
From: sayan @ 2007-06-28 10:15 UTC (permalink / raw)
  To: Caml-list

Robert Roessler wrote:
> sayan@crans.org wrote:
>> I am looking for a floating point version of the function Unix.sleep in
>> order to suspend execution of a program for 0.7s
>>
>> Is there any such function in the standard library ?
>>
>> Is there a solution outside of Threads, and GTK ?
>>
>> I have looked at Unix.interval_timer but I'd rather not use it. From
>> what I understand, you have to add a signal handler to catch sigalrm,
>> and I do not see how to create a sleep function using it.
>>
>> Is there a multiplatform solution ?
> 
> I believe the OCaml idiom for this is to use Unix.select with empty 
> lists for all THREE of the descriptor lists... and this does work on 
> Windows.
> 
> There may be better solutions... ;)
> 
Thanks for the suggestion, I would never have thought of polling for 
this. :)

What about wrapping usleep or nanosleep ? These are probably not 
portable, but are there obvious reasons not include them in the Unix 
library ?

-- 
Sébastien


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

* Re: [Caml-list] Waiting for float time
  2007-06-28 10:15   ` sayan
@ 2007-06-28 10:18     ` Vincent Hanquez
  2007-06-28 11:18       ` Bünzli Daniel
  0 siblings, 1 reply; 13+ messages in thread
From: Vincent Hanquez @ 2007-06-28 10:18 UTC (permalink / raw)
  To: sayan; +Cc: Caml-list

On Thu, Jun 28, 2007 at 12:15:12PM +0200, sayan@crans.org wrote:
> Thanks for the suggestion, I would never have thought of polling for 
> this. :)
> 
> What about wrapping usleep or nanosleep ? These are probably not 
> portable, but are there obvious reasons not include them in the Unix 
> library ?

you have answered the question yourself;
the Unix module is unfortunately a lowest common part of what is
available on lots of unices, and also without "unsafe" stuffs (mmap).
That's why you have to do binding all the times when having specific
low level requirements.

-- 
Vincent Hanquez


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

* Re: [Caml-list] Waiting for float time
  2007-06-27 22:11 ` [Caml-list] " Karl Zilles
@ 2007-06-28 11:15   ` Matthieu Dubuget
  2007-06-28 15:03     ` Bruno Verlyck, Bruno.Verlyck
  0 siblings, 1 reply; 13+ messages in thread
From: Matthieu Dubuget @ 2007-06-28 11:15 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 362 bytes --]

2007/6/28, Karl Zilles <zilles@1969web.com>:
>
> sayan@crans.org wrote:
> > I am looking for a floating point version of the function Unix.sleep in
> > order to suspend execution of a program for 0.7s
>
> Use select with no file_descrs.


Nice! Where are this kind of tricks supposed to be collected?
FAQ, http://www.ocaml-tutorial.org/, ...?

Salutations

Matt

[-- Attachment #2: Type: text/html, Size: 723 bytes --]

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

* Re: [Caml-list] Waiting for float time
  2007-06-28 10:18     ` Vincent Hanquez
@ 2007-06-28 11:18       ` Bünzli Daniel
  0 siblings, 0 replies; 13+ messages in thread
From: Bünzli Daniel @ 2007-06-28 11:18 UTC (permalink / raw)
  To: Caml-list

Le 28 juin 07 à 12:18, Vincent Hanquez a écrit :

>  and also without "unsafe" stuffs (mmap).

Note that mmap is available in a safe way in the Bigarray module.

Daniel


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

* Re: [Caml-list] Waiting for float time
  2007-06-27 22:21 ` Robert Roessler
  2007-06-28 10:15   ` sayan
@ 2007-06-28 11:33   ` Yaron Minsky
  2007-06-29 10:17     ` Robert Roessler
  1 sibling, 1 reply; 13+ messages in thread
From: Yaron Minsky @ 2007-06-28 11:33 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 405 bytes --]

On 6/27/07, Robert Roessler <roessler@rftp.com> wrote:
>
> sayan@crans.org wrote:
>
> I believe the OCaml idiom for this is to use Unix.select with empty
> lists for all THREE of the descriptor lists... and this does work on
> Windows.


Note, on Unix  at least, you need to wrap the call to select in an exception
handler, since select can be interrupted, at which point the call throws an
exception.

y

[-- Attachment #2: Type: text/html, Size: 742 bytes --]

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

* Re: [Caml-list] Waiting for float time
  2007-06-27 21:55 Waiting for float time sayan
  2007-06-27 22:11 ` [Caml-list] " Karl Zilles
  2007-06-27 22:21 ` Robert Roessler
@ 2007-06-28 12:50 ` Thomas Fischbacher
  2 siblings, 0 replies; 13+ messages in thread
From: Thomas Fischbacher @ 2007-06-28 12:50 UTC (permalink / raw)
  To: sayan; +Cc: caml-list

sayan@crans.org wrote:

> I am looking for a floating point version of the function Unix.sleep in
> order to suspend execution of a program for 0.7s


let sleep_float n =
   let _ = Unix.select [] [] [] n in ()
;;


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

* Re: [Caml-list] Waiting for float time
  2007-06-28 11:15   ` Matthieu Dubuget
@ 2007-06-28 15:03     ` Bruno Verlyck, Bruno.Verlyck
  2007-06-28 15:29       ` Matthieu Dubuget
  0 siblings, 1 reply; 13+ messages in thread
From: Bruno Verlyck, Bruno.Verlyck @ 2007-06-28 15:03 UTC (permalink / raw)
  To: Matthieu Dubuget; +Cc: caml-list

   Date: Thu, 28 Jun 2007 13:15:31 +0200
   From: "Matthieu Dubuget" <matthieu.dubuget@gmail.com>

Hi,
   2007/6/28, Karl Zilles <zilles@1969web.com>:
   > sayan@crans.org wrote:
   > > I am looking for a floating point version of the function
   > > Unix.sleep in order to suspend execution of a program for 0.7s
   > Use select with no file_descrs.
   Nice!  Where are this kind of tricks supposed to be collected?
   FAQ, http://www.ocaml-tutorial.org/, ...?
Any book / doc on Unix systems programming ?  This use of select is
standard, unix.cma is only a thin layer over libc and/or the syscalls
(at least from a non-language specific POV).  This is why the (Ocaml)
unix library's documentation starts this way:
   Chapter 21  The unix library: Unix system calls

   The unix library makes many Unix system calls and system-related
   library functions available to Objective Caml programs. This
   chapter describes briefly the functions provided.  Refer to
   sections 2 and 3 of the Unix manual for more details on the
   behavior of these functions.

Bruno.


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

* Re: [Caml-list] Waiting for float time
  2007-06-28 15:03     ` Bruno Verlyck, Bruno.Verlyck
@ 2007-06-28 15:29       ` Matthieu Dubuget
  2007-06-28 15:57         ` Bruno Verlyck, Bruno.Verlyck
  0 siblings, 1 reply; 13+ messages in thread
From: Matthieu Dubuget @ 2007-06-28 15:29 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 1563 bytes --]

2007/6/28, Bruno Verlyck <Bruno.Verlyck@inria.fr>:
>
>    Date: Thu, 28 Jun 2007 13:15:31 +0200
>    From: "Matthieu Dubuget" <matthieu.dubuget@gmail.com>
>
> Hi,
>    2007/6/28, Karl Zilles <zilles@1969web.com>:
>    > sayan@crans.org wrote:
>    > > I am looking for a floating point version of the function
>    > > Unix.sleep in order to suspend execution of a program for 0.7s
>    > Use select with no file_descrs.
>    Nice!  Where are this kind of tricks supposed to be collected?
>    FAQ, http://www.ocaml-tutorial.org/, ...?
> Any book / doc on Unix systems programming ?


Fair answer. But I'm sure you understood my question, didn't you?

I faced exactly the same problem as Sébastien.

I had some OCaml code using Thread module, and, Thread.delay. Because of one
bug in ocaml compilers, I can not use Thread module (
http://caml.inria.fr/mantis/view.php?id=4173).
Not a very big problem after some thought, because the use of Thread was not
absolutely necessary when using my Ocaml code wrapped inside a shared
library. I then looked for a replacement for Thread.delay. I still needed to
wait some (small amount of time) without pooling.

Sorry if I'm not a unix guru, but the fact is that I did not find the
Unix.select solution.

So. Suppose there is some short tricks/recipes list about OCaml somewhere:
it may save time to beginners looking for such things. I asked the question,
because maybe, there is already such a place? (the caml-list archive since
today, at least...)

Salutations

Matthieu Dubuget

[-- Attachment #2: Type: text/html, Size: 2233 bytes --]

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

* Re: [Caml-list] Waiting for float time
  2007-06-28 15:29       ` Matthieu Dubuget
@ 2007-06-28 15:57         ` Bruno Verlyck, Bruno.Verlyck
  0 siblings, 0 replies; 13+ messages in thread
From: Bruno Verlyck, Bruno.Verlyck @ 2007-06-28 15:57 UTC (permalink / raw)
  To: Matthieu Dubuget; +Cc: caml-list

   Date: Thu, 28 Jun 2007 17:29:46 +0200
   From: "Matthieu Dubuget" <matthieu.dubuget@gmail.com>

   2007/6/28, Bruno Verlyck <Bruno.Verlyck@inria.fr>:
   >    Date: Thu, 28 Jun 2007 13:15:31 +0200
   >    From: "Matthieu Dubuget" <matthieu.dubuget@gmail.com>

   >    2007/6/28, Karl Zilles <zilles@1969web.com>:
   >    > sayan@crans.org wrote:
   >    > > I am looking for a floating point version of the function Unix.sleep in
   >    > > order to suspend execution of a program for 0.7s
   >    > Use select with no file_descrs.
   >    Nice!  Where are this kind of tricks supposed to be collected?  FAQ,
   >    http://www.ocaml-tutorial.org/, ...?
   > Any book / doc on Unix systems programming ?
   Fair answer.  But I'm sure you understood my question, didn't you?
I try :-)

   Sorry if I'm not a unix guru, but the fact is that I did not find the
   Unix.select solution.
My point was: it's not an OCaml-related issue (which obviously is not
the answer you expect).

   So.  Suppose there is some short tricks/recipes list about OCaml
About Unix.  I found "The Single UNIX® Specification" worth reading
(as a reference, not as an intro).

   somewhere: it may save time to beginners looking for such things.
   I asked the question, because maybe, there is already such a place?
   (The caml-list archive since today, at least...)
In the caml-list, Xavier often recommends «the books by W. Richard
Stevens ("Advanced Programming in the Unix Environment", "Unix Network
Programming", etc)»; e.g., in
 http://groups.google.com/group/fa.caml/browse_thread/thread/e591ab18a8397a2f/c19874b0c2d5209a?lnk=gst&q=system+programming+book+leroy&rnum=1#c19874b0c2d5209a

Sorry for these frustrating answers :-)
Bruno (who doesn't HTH anymore...)


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

* Re: [Caml-list] Waiting for float time
  2007-06-28 11:33   ` Yaron Minsky
@ 2007-06-29 10:17     ` Robert Roessler
  0 siblings, 0 replies; 13+ messages in thread
From: Robert Roessler @ 2007-06-29 10:17 UTC (permalink / raw)
  To: Caml-list

Yaron Minsky wrote:
> On 6/27/07, *Robert Roessler* <roessler@rftp.com 
> <mailto:roessler@rftp.com>> wrote:
> 
>     sayan@crans.org <mailto:sayan@crans.org> wrote:
> 
>     I believe the OCaml idiom for this is to use Unix.select with empty
>     lists for all THREE of the descriptor lists... and this does work on
>     Windows.
> 
> 
> Note, on Unix  at least, you need to wrap the call to select in an 
> exception handler, since select can be interrupted, at which point the 
> call throws an exception.

Thanks for the reminder - I am too familiar with OCaml's Windows 
version of Unix.select, which recognizes and special-cases the 
"sleep-only" use of select by transforming it into a non-alertable 
[Win32] Sleep() call. ;)

Robert Roessler
roessler@rftp.com
http://www.rftp.com


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

end of thread, other threads:[~2007-06-29 10:18 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-27 21:55 Waiting for float time sayan
2007-06-27 22:11 ` [Caml-list] " Karl Zilles
2007-06-28 11:15   ` Matthieu Dubuget
2007-06-28 15:03     ` Bruno Verlyck, Bruno.Verlyck
2007-06-28 15:29       ` Matthieu Dubuget
2007-06-28 15:57         ` Bruno Verlyck, Bruno.Verlyck
2007-06-27 22:21 ` Robert Roessler
2007-06-28 10:15   ` sayan
2007-06-28 10:18     ` Vincent Hanquez
2007-06-28 11:18       ` Bünzli Daniel
2007-06-28 11:33   ` Yaron Minsky
2007-06-29 10:17     ` Robert Roessler
2007-06-28 12:50 ` Thomas Fischbacher

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 NNTP newsgroup(s).