user77985: Im new to dual core programming and i do not know the best practices yet. In my current project, i would like the second core to only do something after it is being told by the first core.
The approach i am using somewhat of a brute force is something like this:
bool indicator = false;
int a,b;

void loop () { // core1
  if(indicator == false){  //check if core2 is still processing
     a=random(100);
     b=random(100);
     indicator = true;
  }
}

void loop1(){ //core2
  if(indicator == true){
     int sum = a+b;
     Serial.println(sum);
     indicator == false;
  } 
}

this is just a simplified idea of how my code is going to be. Are there better ways of going about this? In general i want to tell core2 from core1 that it needs to start/stop doing something.

user4143: What you have created there is called a semaphore.
In multi-threaded (or multi-core) programming there are two important signalling concepts:

Mutex - This is an object of some form that is used to allow access to a shared resource by only one core or thread at a time.  A thread tries to "lock" a mutex before using a resource.  A mutex can only be "locked" by one thread at a time, and if the mutex is already locked by another thread it can either block (aka a "spinlock") waiting for the mutex to be unlocked, or it can fail gracefully and try again later.
Semaphore - This is a simple flag that is used for one thread to tell another thread that something has happened or that it should do something. It is typically set by one thread then read and cleared by the other thread.

As I mentioned before, a semaphore is what you have created, and a simple boolean value is the most basic semaphore there is. Note, though, that you should really have the variable as volatile to prevent the compiler optimizing it away.
The RP2040 SDK has some functions built in for allowing the cores to communicate, including a "lockout" facility allowing one core to tell the other to stall until such time as it should start processing again, and a FIFO to allow the asynchronous passing of data from one core to the other.

77985: <p>Im new to dual core programming and i do not know the best practices yet. In my current project, i would like the second core to only do something after it is being told by the first core.</p>
<p>The approach i am using somewhat of a brute force is something like this:</p>
<pre><code>bool indicator = false;
int a,b;

void loop () { // core1
  if(indicator == false){  //check if core2 is still processing
     a=random(100);
     b=random(100);
     indicator = true;
  }
}

void loop1(){ //core2
  if(indicator == true){
     int sum = a+b;
     Serial.println(sum);
     indicator == false;
  } 
}
</code></pre>
<p>this is just a simplified idea of how my code is going to be. Are there better ways of going about this? In general i want to tell core2 from core1 that it needs to start/stop doing something.</p>
 4143: <p>What you have created there is called a <em>semaphore</em>.</p>
<p>In multi-threaded (or multi-core) programming there are two important signalling concepts:</p>
<ul>
<li><strong>Mutex</strong> - This is an object of some form that is used to allow access to a shared resource by only one core or thread at a time.  A thread tries to &quot;lock&quot; a mutex before using a resource.  A mutex can only be &quot;locked&quot; by one thread at a time, and if the mutex is already locked by another thread it can either block (aka a &quot;spinlock&quot;) waiting for the mutex to be unlocked, or it can fail gracefully and try again later.</li>
<li><strong>Semaphore</strong> - This is a simple flag that is used for one thread to tell another thread that something has happened or that it should do something. It is typically set by one thread then read and cleared by the other thread.</li>
</ul>
<p>As I mentioned before, a <em>semaphore</em> is what you have created, and a simple boolean value is the most basic semaphore there is. Note, though, that you should really have the variable as <code>volatile</code> to prevent the compiler optimizing it away.</p>
<p>The RP2040 SDK has some functions built in for allowing the cores to communicate, including a &quot;<a href="https://raspberrypi.github.io/pico-sdk-doxygen/group__multicore__lockout.html" rel="nofollow noreferrer">lockout</a>&quot; facility allowing one core to tell the other to stall until such time as it should start processing again, and a <a href="https://raspberrypi.github.io/pico-sdk-doxygen/group__multicore__fifo.html" rel="nofollow noreferrer">FIFO</a> to allow the asynchronous passing of data from one core to the other.</p>
