Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0004023OCaml~DO NOT USE (was: OCaml general)public2006-05-13 17:222017-09-24 17:32
Assigned To 
PlatformOSOS Version
Product Version3.09.2 
Target VersionFixed in Version4.03.0+dev / +beta1 
Summary0004023: usleep feature

it would be very nice to have a function usleep in Unix. Now, there is only sleep that waits for
a given number of seconds, but most of the time, it is not accurate (what if I need to wait 0.1 sec ?)
There is a 'delay' function in Threads, but sometimes, I need to compile without the thread library,
due to external constraints...
So it would be nice to have a usleep function in Unix, that just waits like sleep, but that take a float argument, or a given number of mili or microseconds...

Thank you !
Tagsjunior_job, patch
Attached Filespatch file icon adds-udelay-to-unix.patch [^] (5,154 bytes) 2014-06-22 20:17 [Show Content]
patch file icon adds-udelay-to-unix.2.patch [^] (6,546 bytes) 2014-06-23 10:52 [Show Content]

- Relationships
related to 0007257closedgasche regressions in sleep (Unix.sleep 0) 

-  Notes
berke (reporter)
2006-05-17 11:43

You can use select:

  let usleep t = ignore (select [] [] [] t);;
n8gray (reporter)
2006-08-24 01:55

Great! Include that one-liner in the Unix module and mark the bug fixed. Seriously. Convenience functions make users happy and productive. :)
thizanne (reporter)
2014-06-22 20:23

Just in case, I included a patch which adds this function "more natively". It uses the usleep Unix function for the Unix module (as sleep uses the sleep Unix function). The Thread module also has a Unix module which follows the same interface, but whose implementation is different. I'm not sure exactly how to add or not this operation to threads, I made a compromise adding it to the implementation of the Unix module of threads but not to the interface of the Thread module itself. Also, it is almost exactly equivalent here to `sleep time * 1e-6`, only saving one multiplication by 1e-6.
nevor (reporter)
2014-06-23 09:47

Hello thizanne, you seem to have forgotten the "usleep.c" in your patch. Besides, I have two concerns about usleep, the first one is that this function is deprecated since posix 2001 and the second one is that, at first sight, there is no direct equivalent on Windows. So I'm wondering how the "native" usleep version compares to the one-liner of berke in term of portability and precision.
thizanne (reporter)
2014-06-23 11:47

Sorry for usleep.c, I attached the full patch. As for the Windows availability, I could not test and did not think Unix.sleep worked on Windows anyway, so there was no reason to make Unix.usleep work. I checked today and sleep does work on Windows, however the Sleep(...) from Win32 uses microseconds so it should be usable for usleep. However I see no immediate replacement for nanosleep which apparently replaces usleep in Unix. So in terms of simplicity, the solution with select is definitely ahead - and I saw it while looking for stuff about usleep, so it could be precise enough.
xleroy (administrator)
2015-11-15 17:01
edited on: 2015-11-15 17:01

Implemented as Unix.sleepf in commit [trunk 50648ed]. See [^] for more details.

- Issue History
Date Modified Username Field Change
2006-05-13 17:22 Christophe New Issue
2006-05-17 11:43 berke Note Added: 0003644
2006-08-24 01:55 n8gray Note Added: 0003739
2006-08-29 16:34 doligez Status new => acknowledged
2013-09-03 17:09 doligez Tag Attached: patch
2013-09-03 17:09 doligez Tag Attached: junior_job
2014-06-22 20:17 thizanne File Added: adds-udelay-to-unix.patch
2014-06-22 20:23 thizanne Note Added: 0011770
2014-06-23 09:47 nevor Note Added: 0011771
2014-06-23 10:52 thizanne File Added: adds-udelay-to-unix.2.patch
2014-06-23 11:47 thizanne Note Added: 0011772
2015-11-15 17:01 xleroy Note Added: 0014683
2015-11-15 17:01 xleroy Status acknowledged => resolved
2015-11-15 17:01 xleroy Resolution open => fixed
2015-11-15 17:01 xleroy Fixed in Version => 4.03.0+dev / +beta1
2015-11-15 17:01 xleroy Note Edited: 0014683 View Revisions
2016-05-14 14:48 gasche Relationship added related to 0007257
2017-02-23 16:36 doligez Category OCaml general => -OCaml general
2017-03-03 17:55 doligez Category -OCaml general => -(deprecated) general
2017-03-03 18:01 doligez Category -(deprecated) general => ~deprecated (was: OCaml general)
2017-03-06 17:04 doligez Category ~deprecated (was: OCaml general) => ~DO NOT USE (was: OCaml general)
2017-09-24 17:32 xleroy Status resolved => closed

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker