|
Re: setjmp/longjmp
I want to use them to implement coroutines. The state machines in camera.c and camera_menu.c can get rather cumbersome if something needs to be added, for example submenus. With setjmp and longjmp it is possible to allocate a bit of stack to each "process" and write such a program straight rather than with states and a switch statement. Each process would give up the cpu at appropriate points (roughly corresponding to the end of each state's processing in the FSM) by calling a give-up function, and on the next cycle each process is resumed for its next section using longjmp. I did this once on a VAX, and it worked fairly well, but how to do it is not readily apparent on the FRC. (The VAX C runtime's setjmp and longjmp did not let me tinker with the stack pointer, so I had to write my own setjmp and longjmp functions).
|