arduino / arduino/ArduinoCore-mbed

request: simpler wrappers or use std::thread for multithreading

Open
#208 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
411
Forks
225
PR merge metrics
No merged PRs in 30d

Description

for RP2040 boards (Arduino, Adafruit, Raspberry Pi Pico) and nano33 BLE,
because the current multithreading implementation is very overcomplicated and hard to understand, other than std::thread or pthread:
Will it be possible to provide simpler wrappers for multithreading to have a syntax more like pthread.h or std::thread?
e.g., for a simplified MT blink example:
```
#include

using namespace std;

volatile static int STOP_FLAG=0; // semaphore for thread control

// The function we want to execute on the new thread.
void blink( int pin )
{
pinMode( pin, OUTPUT );
while( STOP_FLAG==0 )
{
digitalWrite(pin, HIGH);
Serial.println("blink thread: pin "+String(pin)+" ON");
delay(500);
digitalWrite(pin, LOW);
Serial.println("blink thread: pin "+String(pin)+" OFF");
delay(500);
}
Serial.println("blink thread: terminated");
}

int main()
{
Serial.println("main: starting thread(s)");
// Constructs the new thread and runs it. Does not block execution.
thread t1( blink, LED_BUILTIN );

// Do other things...
delay(5000); // let all things run for 5sec

Serial.println("main: signal thread(s) to stop");
STOP_FLAG=1; // now set stop flag=true to signal the blink thread to stop it's infinite loop

Serial.println("main: waiting for thread(s) to finish");
t1.join(); // wait for the thread(s) to finish execution, therefore blocks it's own execution.

Serial.println("main: finished");
}
```
instead of main() one also might do the thread creation in the common Arduino setup() function and then do other things repeatedly, additionally, in the standard loop() as usual.

Contributor guide

No contributing guide indexed for this repository

Research direction

The request does not identify a file or test; start by locating the current multithreading implementation for the RP2040 and Nano 33 BLE targets. Compare its public API with std::thread or pthread and the proposed setup()/loop() usage. Done would require an agreed wrapper design plus examples or tests covering thread creation, stopping, and join behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
embedded-iot
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.