-3

I am currently trying to make a little robot thing using a Raspberry Pi Pico W, and I have most things working at the moment. However, I currently need to have a way to sort of schedule things, having certain periodicals at different times, etc.

The issue I have is that whenever I use the std::thread library, I get the same error message, no matter what I do.

no matching function for call to 'std::thread::thread(void (*)())'

Even with code that compiles and runs perfectly fine outside the pico environment.

For instance,

#include <iostream>
#include <thread>

using namespace std;

void myFunc() {
    cout << "hello, world!" << endl;
}
int main() {
    thread myThread(&myFunc);
    myThread.join();
}

This code results in the error shown above.

Edit with some further information:

  • This is using the Raspberry Pi Pico extension on VSCode
  • This is on an M1 Mac
  • SDK version is 2.1.1
17
  • 1
    Typo? std::thread myThread(myFunc);. Or use a lambda expression: std::thread myThread([]{ myFunc(); } this last option is nice for later too since you can capture data (in the []) and pass it on to the thread. Commented Feb 25 at 4:49
  • 2
    Both cause the same error, and &myFunc is technically the same as myFunc. Commented Feb 25 at 4:50
  • 1
    It seems weird, it should work : onlinegdb.com/8RrCM6RBq. And it must be that you compile with at least C++11 since the <thread> header can be found. What compiler (settings) and compiler version are you using? Commented Feb 25 at 4:52
  • 2
    Are you sure that the Pico supports threads? Commented Feb 25 at 5:22
  • 2
    Looks like it doesn't github.com/raspberrypi/pico-sdk/issues/1901 see raspberrypi.com/documentation/pico-sdk/… Commented Feb 25 at 5:33

1 Answer 1

1

I have found a working solution (for my needs) using the pico sdk multicore library.

As I understand it, using just the default pico SDK, you cannot use any multithreading, such as <thread> or <pthread.h>. However, the pico SDK comes with a useful library called pico/multicore.h. It allows you to use the second core.

Sign up to request clarification or add additional context in comments.

1 Comment

I got a bit inspired by your question and wanted to try to write a wrapper around pthread_create / pthread_join like std::thread. This is the start: godbolt.org/z/8jEKrnTKs - note that it's missing a few member functions and that you need to write your own pthread wrapper to replace std::mutex.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.