Coroutines in C
S. Manoharan
sam at lfcs.ed.ac.uk
Wed Aug 23 07:40:20 AEST 1989
In article <5773 at ficc.uu.net> peter at ficc.uu.net (Peter da Silva) writes:
>
> In many C compilers I wouldn't even need
>to write any assembly code, since setjmp/longjmp can be used to implement
>the context switch.
I have a question. Consider these functions:
event1() event2()
{ {
. . . . . .
get_resourceX(); . . .
/*resume:*/ . . . . . .
} }
event1() requsts for resourceX. If resourceX is not available
then I want event1() to suspend, and some other event, say
event2() to start. Perhaps, event2() could make the resourceX
available. Once the resourceX is available, I want the function
event1() to start from the /*resume:*/ point. (The code upto
the /*resume:*/ point in event1() should not be re-executed)
Intutively, it appears the co-routines could be applied in this
context. Am I correct?
And then, is there an easy way to tackle this problem?
Since there could be a number of event?()s, I think setjmp()
and longjmp() would be of no help.
Janet: sam at uk.ac.ed.lfcs S. Manoharan
Uucp : ..!mcvax!ukc!lfcs!sam Dept of Computer Science
Arpa : sam%lfcs.ed.ac.uk at nsfnet-relay.ac.uk University of Edinburgh
Voice: 031-667 5076 (home) Edinburgh EH9 3JZ UK.
More information about the Comp.lang.c
mailing list