next up previous
Next: Structured Dagger Up: Event-Driven Objects Previous: Event-Driven Objects

Return-Switch Functions

A C or C++ subroutine can be written in a return-switch style to mimic thread suspend/resume. When the subroutine is ``suspended'', it returns instead of blocking with a flag indicating the point it left off. When the subroutine is ``resumed'', the same subroutine is called with the flag which can then be used in a ``goto'' or ``switch'' statement to resume execution at the point it left off. It is possible to wrap a technique similar to Duff's Device inside a set of macros to make this ``save, return, and resume from label'' process mostly transparent to the programmer [37]. However this technique can still be confusing, error-prone and tough to debug.



Gengbin Zheng 2006-03-18