iphone - is it ok to use usleep on a secondary thread on Grand Central Dispatch?
-
10-10-2019 - |
문제
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.
해결책
You just need to include the appropriate header before calling usleep():
#include <unistd.h>
제휴하지 않습니다 StackOverflow