# Multicore on the RP2040
The RP2040 microcontroller has 2 ARM Cortex-M0+ cores. In previous courses, however, we only utilised 1 of them. Today, we are going to unleash the full computing power on the RP2040 and use both of the cores.
## Getting Started
It is very simple to run with both cores with the Pico-SDK, there is a helpful pico-multicore library with which we can run code and exchange data between the two cores. We only need to write an extra main function to run on core 1 and launch it with the main function running on core 0.
``` c=
#include <stdio.h>
#include "pico/multicore.h"
#include "pico/stdlib.h"
// main function for core 1
void core1_entry(void)
{
while (true)
{
printf("Sent from core 1, time: %d\n",
to_us_since_boot(get_absolute_time()));
sleep_ms(1000);
}
}
// main function for core 0
int main(void)
{
stdio_init_all();
// launch main function to run on core 1
multicore_launch_core1(core1_entry);
sleep_ms(500);
while (true)
{
printf("Sent from core 0, time: %d\n",
to_us_since_boot(get_absolute_time()));
sleep_ms(1000);
}
}
```
## Memory
Both core 0 and core 1 can access the RAM at the same time. If both cores tries to modify the same data at the same time, this creates a race condition. For example, core 0 increments N by 1 every time and core 1 increments N by 2 every time. If both cores tries to increment N, what should the result be?
In order to prevent this kind of uncertainty, various schemes are implemented to prevent race conditions. There are software solutions such as mutex and semaphore to ensure only 1 core has the privilege to access the chunk of data at one instance. Today, we are only going to discuss about the hardware FIFO implemented on the RP2040.
There are two 8-entry, 32-bit FIFOs between the two cores. One goes from core 0 to core 1, while the other goes from core 1 to core 0.

When we want to write data into the FIFO to send to the other core, we call the `multicore_fifo_push_blocking()` function. Note that the data has to be a 32-bit value. We can use `multicore_fifo_wready()` to check if the FIFO has space.
``` c=
if(multicore_fifo_wready()) {
multicore_fifo_push_blocking(data);
}
```
When we want to read data from the FIFO, we call the `multicore_fifo_pop_blocking()` function. Same as writing to the FIFO, the data is a 32-bit value. We can also use the `multicore_fifo_rvalid()` function to check if there is data available to read.
``` c=
if(multicore_fifo_rvalid()) {
data = multicore_fifo_pop_blocking();
}
```
## Reference
[More detailed explaination and example of intercore FIFO](https://learnembeddedsystems.co.uk/basic-multicore-pico-example)