sleep(), usleep()和[NSThread sleepForTimeInterval:]

来源:互联网 发布:强矩阵管理模式 编辑:程序博客网 时间:2024/06/16 16:28

引用一段stackoverflow上的回答

sleep(3) is a posix standard library method that attempts to suspend the calling thread for the amount of time specified in seconds. usleep(3) does the same, except it takes a time in microseconds instead. Both are actually implemented with the nanosleep(2) system call.

The last method does the same thing except that it is part of the Foundation framework rather than being a C library call. It takes an NSTimeInterval that represents the amount of time to be slept as a double indicating seconds and fractions of a second.

For all intents and purposes, they all do functionally the same thing, i.e., attempt to suspend the calling thread for some specified amount of time.

原帖地址:

http://stackoverflow.com/questions/3155586/what-is-the-difference-among-sleep-usleep-nsthread-sleepfortimeinterval

原创粉丝点击