In Wikipedia https://en.wikipedia.org/wiki/Setcontext there is the following procedure, understand this applet, basically to ucontext this execution context switch of the library can also understand a similar.
#include <stdio.h> #include <ucontext.h> #include <unistd.h>int Main (int argc, const char *argv[]) {ucontext_t context; GetContext ( &context); Puts ( hello World " ); Sleep ( 1 ); SetContext ( &context); return 0 ;}
Let's look at the logic of this program. GetContext (&context); This statement is to place the current context into the variable ucontext_t context. and SetContext (&context); This statement is interpreted in English as: This function transfers control to the context in ucontext_t context. Execution continues from the point at which the context is stored in ucontext_t context. Chinese translation here means: the current function (that is, the main function The transfer is controlled to the context stored in the contextual variable, and execution continues from the store context to the point of the context variable. So the result of this app is: Infinite loop print Hello World, do you understand? To understand that basically Ucontext also understand a lot of.
[Linux] comments on a small program of the Ucontext library @ C language