context/main.c
/* This is the iterator function. It is entered on the first call to
 * swapcontext, and loops from 0 to 9. Each value is saved in i_from_iterator,
 * and then swapcontext used to return to the main loop.  The main loop prints
 * the value and calls swapcontext to swap back into the function. When the end
 * of the loop is reached, the function exits, and execution switches to the
 * context pointed to by main_context1. */
This is the iterator function. It is entered on the first call to
swapcontext, and loops from 0 to 9. Each value is saved in i_from_iterator,
and then swapcontext used to return to the main loop.  The main loop prints
the value and calls swapcontext to swap back into the function. When the end
of the loop is reached, the function exits, and execution switches to the
context pointed to by main_context1.
This is the iterator function . It is entered on the first call to swapcontext and loops from 0 to 9 . Each value is saved in i_from_iterator and then swapcontext used to return to the main loop . The main loop prints the value and calls swapcontext to swap back into the function . When the end of the loop is reached the function exits and execution switches to the context pointed to by main_context1 .
void loop(
		ucontext_t *loop_context,
		ucontext_t *other_context,
		int *i_from_iterator)
{
	int i;
	for (i=0; i < 10; ++i) {
		*i_from_iterator = i;
		swapcontext(loop_context, other_context);
	}
}
void loop ( ucontext_t * loop_context , ucontext_t * other_context , int * i_from_iterator ) { int i ; for ( i = 0 ; i < 10 ; ++ i ) { * i_from_iterator = i ; swapcontext ( loop_context , other_context ) ; } }
This is the iterator function.
This is the iterator function .
/* Write the loop counter into the iterator return location. */ /* Save the loop context (this point in the code) into ''loop_context'',
		 * and switch to other_context. */ /* The function falls through to the calling context with an implicit
	 * ''setcontext(&loop_context->uc_link);'' */