• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Co-Routine in C programming

Status
Not open for further replies.

Parth86

Member
Hi
I am trying to understand what is Co-Routine in Embedded Programming. Co-routine in program allow multiple entry points for suspending and resuming execution at certain locations. I was looking small example to understand co-routine. I found this code example. but I don't understand how does co-routine work in real program I am trying to make small embedded program please help me to implement co-routine in c program related with embedded task.
C:
#include <setjmp.h>

int main (void)
{
  jmp_buf buf1;
 
  if (setjmp(buf1) == 0)
  {
   /* This code is executed on the first call to setjmp. */

   longjmp(buf1, 1);
  } else {
   /* This code is executed once longjmp is called. */
  }
  return 0;
}
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
Don't go there!!!

These examples are for higher level programming.... If you start introducing jumps into C a whole heartache of misery will come to light....

C works with a software stack!! Entering a sub routine / function / procedure certain housekeeping tasks must be done.. This kind of programming dismisses all this... I wouldn't entertain it and I'm pretty well versed in assembler..

I don't even use goto's in C....

If your first question is :- "What's a software stack" .. Then I rest my case!
 

Parth86

Member
Don't go there!!!

These examples are for higher level programming.... If you start introducing jumps into C a whole heartache of misery will come to light....

C works with a software stack!! Entering a sub routine / function / procedure certain housekeeping tasks must be done.. This kind of programming dismisses all this... I wouldn't entertain it and I'm pretty well versed in assembler..

I don't even use goto's in C....

If your first question is :- "What's a software stack" .. Then I rest my case!
Thanks for your quick response. actually I was reading topic "Co-routine". than I searched on google. I was looking for specific example that define what is co-routine and when does it use in program and if I understand basic than I tried to implement in program. Software stack are different topics. If you can help with hand made code or algorithm means just want to understand first what is co-routine and when does it use in program?
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
Software stacks in C are used for calling functions... Coroutines are functions that have several entry points, you need to tread very carefully as they do not keep the stack updated..

There are far better ways in C to achieve dynamic programming.. The best in my view are function pointers and pointer pointers...

I think coroutines are mainly used in RTOS environments where multiple stacks are used.. Jumping from task to task outside of the normal kernel. Even the guy's who implemented this form of access fear its use..

As far as I'm concerned, Leaving a stack untouched and leaving a function to enter another mid point requires a third stack to oversee the procedure.. Messy.. very messy and I haven't the knowledge to help... The only other guy who messes around with this stuff is MrT and I haven't seen him for a while..
 

Cicero

Active Member
I agree with Nigel. I've seen your questions recently and suggest you focus on more simpler programming concepts.

No offence intended, we all have to start somewhere. No point in trying to drive an F1 car when you've just started learning to drive.
 

be80be

Well-Known Member
Coroutines Are not really for a uC microcontroller
Coroutines are computer program components that generalize subroutines for non-preemptive multitasking, by allowing multiple entry points for suspending and resuming execution at certain locations.
 
Status
Not open for further replies.

EE World Online Articles

Loading
Top