YIELDING AND SUSPENDING
At times, you may want to control the behavior of your fiber execution more than the simple control provided by executing a single statement at a time. Two methods are provided for you to do so. Both methods are invoked by a wrapper function to affect the execution of the fiber the wrapper functions is within.
When a wrapper function is ready to return, it sets up its value in the SE_RETURN object. Two members of the object, SE_YIELD and SE_SUSPEND, can likewise be set. Both are boolean members and are set TRUE to invoke their relevent behavior.
First is SE_YIELD. By yielding, the fiber ensures that the current seExec statement is immediately ended. Recall that the SE_INFREQUENT_CONT option to seEval means that several statements are executed for each call to seExec. If a wrapper function yields, the seExec returns immediately. The return value for the wrapper function is still treated normally. The next time the fiber is executed using seExec, execution resumes with the code that called the wrapper function getting that value as the return.
The second option is SE_SUSPEND. Suspending functions is similar to yielding in that the calling seExec finishes immediately. However, the fiber is put into a suspended state. This means that further calls to seExec will immediately return without executing any code of the fiber. It is the job of your application to determine when the fiber is ready to be restored and remove its suspended state. This is done by assigning FALSE to the fiber’s SE_RETURN,SE_SUSPEND member. After the suspend is removed, the application can also change the return value to be returned by the wrapper function before again executing any code. It does this by assigning the new value to the SE_RETURN,SE_VALUE member as normal. If it does not, the value returned by the wrapper function is used. This is useful if the value to be returned is unknown when the wrapper function suspended, perhaps that is why it needed to be suspended. Remember, though, that the SE_RETURN,SE_VALUE member is read-only as long as any of the boolean members are TRUE including the SE_SUSPEND member. You must turn the suspension off before you are allowed to write a new return value. Of course, you must do it also before you call seExec on the fiber after it is unsuspended.