问题
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