本文介绍了iphone - 可以在Grand Central Dispatch的辅助线程上使用usleep吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Grand Central Dispatch将一个块添加到队列(而不是主队列)。该块具有环路,并且在环路的每个通道之间需要0.22秒的小延迟。我正在使用

I am adding a block to a queue (not the main queue), using Grand Central Dispatch. This block has a loop and between every passage of the loop a small delay of 0,02 seconds is required. I am using

dispatch_async(myOwnQueue, ^{
  // begin loop
  // do stuff
  usleep(20000);
  // end loop
});

。因为它不是主队列,所以它不会阻塞主线程。

on this queue. As it is not the main queue, it will not block the main thread.

问题是Xcode抱怨:警告:隐式声明函数'usleep'

The problem is that Xcode complains: warning: implicit declaration of function 'usleep'

还有其他办法吗?

谢谢。

推荐答案

您只需要在调用usleep()之前包含相应的标题:

You just need to include the appropriate header before calling usleep():

#include <unistd.h>

这篇关于iphone - 可以在Grand Central Dispatch的辅助线程上使用usleep吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-19 01:13