iphone - is it ok to use usleep on a secondary thread on Grand Central Dispatch?

。_饼干妹妹 提交于 2019-12-09 02:09:29

问题


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.

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

Is there other way to do that?

thanks.


回答1:


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

#include <unistd.h>


来源:https://stackoverflow.com/questions/4668634/iphone-is-it-ok-to-use-usleep-on-a-secondary-thread-on-grand-central-dispatch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!