Code with Global Variables but separate for each Core
in C/C++
Hi,
I am developing some code in C, which I want to use with P2 and RPI PICO (Ardino C++). I have started with the version for P2 with FlexC.
The same code using some global variables must run independently in more than one COG. In FlexC for P2 this can be achieved with "extern register int". These variables share the name but not the value, which is, what I need.
RPI PICO has 2 cores, so I would like to use the second one in a similar way. But I have found no similar means in C++ to have global variables, separate for 2 cores?!? An array with the core-number as index? There must be a better way!
Thank for any hints!
Christof
Comments
Probably not too many folks here have familiarity with the Pico, including me. I have done a little STM32 (also Cortex-M) C programming in the past and found 2-core programming to be awkward at best (I abandoned it). If I had to do multicore on a small machine that is not a P2, I would use go with hardware multi-threading on a (non-Pico) RPi, with all its pros and cons. However, that combination might be OK if you use the P2 for real-time and the RPi for best-effort processing.
I don't know specifically about the Pico, but in general I think what you're looking for is called "thread local storage".
Thank you for the inputs!
Yes, sometimes the right name is a great advantage! Thank you, Eric!