micro-os-plus/micro-os-plus-iii

Allow lambdas with captures as thread functions

Opened this issue · 3 comments

This is already possible because non-capturing lambdas can be converted to function pointers

thread testThread
{
  [](void* arg) -> void*
  {
    return arg;
  },
  nullptr
};

Would be great if this also would

int val;
thread testThread
{
  [&val](void* arg) -> void*
  {
    return arg;
  },
  nullptr
};

Not sure how difficult that would be though..

If this is supported by the C++ standard, and is implemented in the current g++, then it should be possible in µOS++ too.

If I use the estd api, then yes, it seems to work (which is good!).
I was referring to the RTOS C++ api which I am normally using because the standard interface doesn't allow to set a stack size.

Feel free to suggest improvement to the RTOS native API.

It is true that the standard API does not allow to set the stack size, but you can set the default stack size and then create standard threads. The disadvantage is that this will use dynamically allocated memory.