Stackless `protothreads' using computed goto's

A

aarklon

Hi all,

in the web page http://pramode-ce.livejournal.com/2006/01/18/

it is given as follows

The GNU Compiler offers an interesting extension by which you can
store the address of a label in a pointer variable.

main()
{
void *p;
p = &&L1;
goto *p;
printf("hello\n");
L1: printf("world\n");
}

The `protothread library', available from this site, uses this GCC
extension and some simple preprocessor magic to develop a very low
overhead non-preemptive multithreading system suitable for use in
severly memory constrained systems. There is also an alternate
implementation based on a clever use of the switch-case statement. The
source code is recommended reading for people interested in creative C
coding! I was able to use the code unchanged for writing a toy
non-preemptive tasking system for my ARM7 CPU

now my questions are as follows

1) Is it possible to implement such a functionality in ANSI C ??

2)what is this alternate implementation based on a clever use of the
switch-case statement.??
can anybody give examples??
 
M

mark_bluemel

Hi all,

in the web page http://pramode-ce.livejournal.com/2006/01/18/

it is given as follows

The GNU Compiler offers an interesting extension by which you can
store the address of a label in a pointer variable.

main()
{
void *p;
p = &&L1;
goto *p;
printf("hello\n");
L1: printf("world\n");
}

The `protothread library', available from this site, uses this GCC
extension and some simple preprocessor magic to develop a very low
overhead non-preemptive multithreading system suitable for use in
severly memory constrained systems. There is also an alternate
implementation based on a clever use of the switch-case statement. The
source code is recommended reading for people interested in creative C
coding! I was able to use the code unchanged for writing a toy
non-preemptive tasking system for my ARM7 CPU

now my questions are as follows

1) Is it possible to implement such a functionality in ANSI C ??

2)what is this alternate implementation based on a clever use of the
switch-case statement.??
can anybody give examples??

Look at
<http://groups.google.co.uk/group/co...d?lnk=gst&q=duff&rnum=1&#doc_2346b958e66abc2c>
and follow the links from that for a start...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top