什么是sleep(),usleep()& [NSThread sleepForTimeInterval:]? [英] what is the difference among sleep() , usleep() & [NSThread sleepForTimeInterval:]?
问题描述
任何东西可以解释我sleep(),usleep()& [NSThread sleepForTimeInterval:]?
Can any body explain me what is the difference among sleep() , usleep() & [NSThread sleepForTimeInterval:] ?
使用这些方法的最佳条件是什么?
What is the best condition to use these methods ?
推荐答案
sleep(3)是一个posix标准库方法,试图挂起调用线程的时间量(以秒为单位)。 usleep(3)也是这样,除了它需要一个微秒的时间。两个都是用nanosleep(2)系统调用实现的。
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.
最后一个方法做同样的事情,除了它是Foundation框架的一部分,而不是一个C库呼叫。它需要一个NSTimeInterval来表示睡眠的时间量,作为双重指示秒和几分之一秒。
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.
这篇关于什么是sleep(),usleep()& [NSThread sleepForTimeInterval:]?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!