Patent ID: 7559063

Claim:
A method for running application programs supporting multiple contexts on a computer system, the method comprising: processing a context processing instruction from said run-time application program; evaluating said instruction in relation to program-flow control yielding context-defining processing parameters; analyzing said context-defining processing parameters from the execution context of said context processing instruction in regard of program flow management by threads; mapping said context-processing instruction to a selected thread managing instruction or to a selected set of thread managing instructions, having a respective program flow control effect equivalent to that of said context-processing instruction; invoking said selected thread managing instruction or said set thereof, together with selected parameters for guaranteeing that during runtime of said application program; only one thread is allowed to execute at a time using at least one semaphore, and the program state of a thread to be stored at a point in time and to be restored later from said point in time, wherein a setjmp-equivalent operation is used for storing the CPU state at any given point in time, and a longjmp-equivalent operation is used for restoring the CPU state at any later point in time; and swapping between contexts by executing a getcontext function followed by executing a setcontext function, wherein the setcontext function suspends a thread of an active context, releases a thread of a destination context by releasing an associated semaphore, and then loads a CPU with a register set stored in a CPU snapshot by calling a longjmp-equivalent operation with information recorded by an associated getcontext function, wherein if the destination thread has not ended, the CPU is loaded with the snapshot from the getcontext function, or if the destination thread has ended, any thread resources allocated during a makecontext function are freed.