在OCaml中睡眠不到一秒钟 [英] Sleeping less than a second in OCaml

查看:81
本文介绍了在OCaml中睡眠不到一秒钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Unix.sleep函数可以将程序挂起整秒钟,但是如何将其挂起不到一秒钟呢?

The Unix.sleep function can suspend the program for whole seconds, but how can you suspend it for less than a second?

推荐答案

为此,经典的Unix解决方案是使用没有文件描述符的select():

The classical Unix solution for this is to use select() with no file descriptors:

let minisleep (sec: float) =
    ignore (Unix.select [] [] [] sec)

这篇关于在OCaml中睡眠不到一秒钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆