Shop OBEX P1 Docs P2 Docs Learn Events
cogstart in propeller.h vs _start_cog_thread in thread.h — Parallax Forums

cogstart in propeller.h vs _start_cog_thread in thread.h

What's the difference between cogstart in propeller.h vs _start_cog_thread in thread.h? Aside from the function signatures which I can read for myself.

Comments

  • Okay, I've answered this for myself.

    cogstart from propeller.h uses the provided stack to create the _thread_state variable instance and then invokes _start_cog_thread. It also saves the user from having to calculate the address of the top of the stack. All-in-all, it looks like it should always be favored over _start_cog_thread directly.
  • DavidZemonDavidZemon Posts: 2,973
    edited 2015-12-31 16:01
    The _thread_state_t variable is considerably larger than I was expecting it to be. Using CMM or LMM, there is a minimum stack size of 45 longs! That's quite a bit larger than I was expecting, but certainly good to know isn't it?

    cogstart contains a simple stack size check and, if the stack isn't large enough, will error out by returning -1 if it isn't large enough. So, for a simple cog that blinks an LED, 45 should be fine (I use 64 in PropWare's examples because I like powers of 2) and more complicated functions you'll want to increase simply by trial and error.
Sign In or Register to comment.