Site icon Bytefreaks.net

Alternative to sched_yield()

Advertisements

In case sched_yield() does not seem to work for you or it is not available, you can try calling usleep(0) as a workaround.

int sched_yield(void); from (#include <sched.h>) causes the calling thread to relinquish the CPU. The thread is moved to the end of the queue for its static priority and a new thread gets to run.
From: man 3 sched_yield

int usleep(useconds_t usec); from (#include <unistd.h>) suspends execution of the calling thread for (at least) usec microseconds. The sleep may be lengthened slightly by any system activity or by the time spent processing the call or by the granularity of system timers.
From: man 3 usleep

Notes

This post is also available in: Greek

Exit mobile version