Allow another thread to run.
CS_RETCODE srv_yield()
None.
#include <stdio.h>
#include <ospublic.h>
/*
** Local Prototype.
*/
CS_RETCODE ex_srv_yield PROTOTYPE((
));
/*
** EX_SRV_YIELD
**
** Example routine to suspend the current thread.
** Arguments:
** None.
**
** Returns:
**
** CS_SUCCEED
** CS_FAIL
*/
CS_RETCODE ex_srv_yield()
{
printf(“I’ll wait this one out...\n”);
if (srv_yield() == CS_FAIL)
{
printf(“srv_yield() failed.\n”);
return(CS_FAIL);
}
else
{
printf(“I’m back!\n”);
return(CS_SUCCEED);
}
}
srv_yield suspends the current thread and allows another runnable thread of the same or higher priority to run. The thread is rescheduled at a later time.
srv_yield is primarily useful when using non-preemptive scheduling.
If a thread calls srv_yield to allow a new thread which is still being established to run:
Open Server completes establishing the new thread.
If the new thread does not become runnable it will not gain control and the current thread will seem to get control back immediately.
Refer to “Multithread programming”.
The thread that calls srv_yield will resume execution at the statement following srv_yield.
srv_yield cannot be used in a SRV_START handler.
Do not call srv_yield from interrupt level code.