ESP32c3 - single threaded?

papadeltasierra
Posts: 28
Joined: Thu Nov 03, 2022 1:57 pm

ESP32c3 - single threaded?

Postby papadeltasierra » Wed Nov 22, 2023 10:24 am

I believe the ESP32c3 only has a single core so two questions:
1. Does it still build using the ESP modified multi-core version of FreeRTOS or does it use the standard single-threaded version?
2. Do I need to worry about locking or can I be 100% sure that only one task at a time can be running and accessing data?
Thanks.

MicroController
Posts: 1708
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: ESP32c3 - single threaded?

Postby MicroController » Wed Nov 22, 2023 12:47 pm

papadeltasierra wrote:
Wed Nov 22, 2023 10:24 am
I believe the ESP32c3 only has a single core so two questions:
Yes, it's single-core.
1. Does it still build using the ESP modified multi-core version of FreeRTOS or does it use the standard single-threaded version?
Yes and no. It uses the same Espressif-FreeRTOS code, but built to run on a single core. That's not a "single-threaded" version though.
2. Do I need to worry about locking or can I be 100% sure that only one task at a time can be running and accessing data?
You do need to manage synchronization ("locking") because the OS is preemptive, which to an individual task is indistinguishable from true concurrency. Plus there are all the other interrupts.
However, when separating tasks' data and having them communicate via proper inter-task means (queues, semaphores,...) you won't need much 'manual' synchronization.

papadeltasierra
Posts: 28
Joined: Thu Nov 03, 2022 1:57 pm

Re: ESP32c3 - single threaded?

Postby papadeltasierra » Wed Nov 22, 2023 1:58 pm

Thanks for that info. I was idly wondering "how might I pass a lot of data between tasks" and passing the pointer to a shared buffer would be one way, but would need some sort of protection in this case.

MicroController
Posts: 1708
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: ESP32c3 - single threaded?

Postby MicroController » Wed Nov 22, 2023 3:01 pm

Yes, a shared buffer is a valid use case which may require locking, or some other way of ensuring exclusive use of the buffer at any given time. Passing (pointers to) buffers back and forth between tasks ping-pong style via two queues can also do the trick, or using the IDF's ring buffer, for example.

Who is online

Users browsing this forum: MicroController and 124 guests