引用一段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
本文解释了POSIX标准库中的sleep()和usleep()方法,以及Foundation框架中的NSThread.sleepForTimeInterval()方法之间的区别。它们都是通过调用nanosleep(2)系统调用来实现线程暂停的功能。
3713

被折叠的 条评论
为什么被折叠?



