user77985: I would like to use queuing because i think its best for my application. I have very limited experience in dual core programming all i want is to hopefully pass 32 bit numbers to the second core properly. queuing seems to be good because it makes sure that the second core who is receiving the data wont miss anything in the sequence if data comes in very fast and core 2 is not ready to process it.
But Im having trouble finding examples. I did find one but its for a runner queue, which i think is a bit different to what i want
Can anyone show me an example sketch? what i would really like to see is core 1 adding to the queue and core 2 retrieving and removing data from the queue

user65894: This requires a thread-safe queue, where one thread writes to the queue, and another thread reads from the queue.
But I find that with a little care, you can just use a circular buffer where the consumer will increase the head, and the producer will increase the tail.
Something like this:
#define MAXSZ 80
static int buff[MAXSZ];
static int head=0;
static int tail=0;

bool full(void)  { return (tail+1)%MAXSZ == head; }
bool empty(void) { return head==tail; }
int  usage(void) { int num = tail-head; return num<0 ? num+MAXSZ : num; }


int produce(int val)
{
   if ( full() ) return -1;
   buff[tail] = val;
   tail = (tail+1)%MAXSZ;
   return 0; // signal success.
}

int consume(void)
{
   if ( empty() ) return -1;
   int val = buff[head];
   head = (head+1)%MAXSZ;
}


This will work as long as your compiler doesn't do crazy re-ordering of the operations, and as long as you only touch the head with the consumer, and only touch the tail with the producer. Also, the assignments of head/tail need to be atomic, not split up as: tail++ ; tail = tail%MAXSZ;
Come to think of it: if a small capacity suffices, like the 80 from the example code, I would use int8_t for head/tail, just in case writing an int to memory gets context-switched between writing the LSB and MSB parts. (I don't know RP2040 well enough to know if writing an int is atomic.)

user77985: After digging around i was able to use the queue_t from the sdk. and here it is
queue_t queue;

typedef struct queueItem {
  uint32_t value;
} item;

const int QUEUE_LENGTH = 128;


void setup() { //CORE 1 setup

  Serial.begin(9600);
  while (!Serial);
  queue_init(&queue, sizeof(item), QUEUE_LENGTH); //initialize the queue

}

void loop() { //CORE 1 TIGHTLOOP

  queueItem temp;
  temp.value = random (1000);
  if (queue_try_add(&queue, &temp)) { //adding items to the queue
    Serial.print("ADDING:\t");
    Serial.println(temp.value);
  }

  else
    Serial.println("FIFO was full\n");
  delay(500);
}

void setup1() { // CORE2
}

void loop1() {  //CORE 2 TIGHTLOOP

  queueItem temp;
  while (queue_try_remove(&queue, &temp)) { //retrieving item from the queue and deleting it from the queue
    Serial.print("ITEM RETRIEVED:\t");
    Serial.println(temp.value);
  }

  delay(500);


}


77985: <p>I would like to use queuing because i think its best for my application. I have very limited experience in dual core programming all i want is to hopefully pass 32 bit numbers to the second core properly. queuing seems to be good because it makes sure that the second core who is receiving the data wont miss anything in the sequence if data comes in very fast and core 2 is not ready to process it.</p>
<p>But Im having trouble finding examples. I did <a href="https://github.com/raspberrypi/pico-examples/blob/master/multicore/multicore_runner_queue/multicore_runner_queue.c" rel="nofollow noreferrer">find one</a> but its for a runner queue, which i think is a bit different to what i want</p>
<p>Can anyone show me an example sketch? what i would really like to see is core 1 adding to the queue and core 2 retrieving and removing data from the queue</p>
 65894: <p>This requires a thread-safe queue, where one thread writes to the queue, and another thread reads from the queue.</p>
<p>But I find that with a little care, you can just use a circular buffer where the consumer will increase the head, and the producer will increase the tail.</p>
<p>Something like this:</p>
<pre><code>#define MAXSZ 80
static int buff[MAXSZ];
static int head=0;
static int tail=0;

bool full(void)  { return (tail+1)%MAXSZ == head; }
bool empty(void) { return head==tail; }
int  usage(void) { int num = tail-head; return num&lt;0 ? num+MAXSZ : num; }


int produce(int val)
{
   if ( full() ) return -1;
   buff[tail] = val;
   tail = (tail+1)%MAXSZ;
   return 0; // signal success.
}

int consume(void)
{
   if ( empty() ) return -1;
   int val = buff[head];
   head = (head+1)%MAXSZ;
}

</code></pre>
<p>This will work as long as your compiler doesn't do crazy re-ordering of the operations, and as long as you only touch the head with the consumer, and only touch the tail with the producer. Also, the assignments of head/tail need to be atomic, not split up as: <code>tail++ ; tail = tail%MAXSZ;</code></p>
<p>Come to think of it: if a small capacity suffices, like the 80 from the example code, I would use <code>int8_t</code> for head/tail, just in case writing an int to memory gets context-switched between writing the LSB and MSB parts. (I don't know RP2040 well enough to know if writing an int is atomic.)</p>
 77985: <p>After digging around i was able to use the queue_t from the sdk. and here it is</p>
<pre><code>queue_t queue;

typedef struct queueItem {
  uint32_t value;
} item;

const int QUEUE_LENGTH = 128;


void setup() { //CORE 1 setup

  Serial.begin(9600);
  while (!Serial);
  queue_init(&amp;queue, sizeof(item), QUEUE_LENGTH); //initialize the queue

}

void loop() { //CORE 1 TIGHTLOOP

  queueItem temp;
  temp.value = random (1000);
  if (queue_try_add(&amp;queue, &amp;temp)) { //adding items to the queue
    Serial.print(&quot;ADDING:\t&quot;);
    Serial.println(temp.value);
  }

  else
    Serial.println(&quot;FIFO was full\n&quot;);
  delay(500);
}

void setup1() { // CORE2
}

void loop1() {  //CORE 2 TIGHTLOOP

  queueItem temp;
  while (queue_try_remove(&amp;queue, &amp;temp)) { //retrieving item from the queue and deleting it from the queue
    Serial.print(&quot;ITEM RETRIEVED:\t&quot;);
    Serial.println(temp.value);
  }

  delay(500);


}
</code></pre>
