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

The portable part of µOS++ IIIe (an xpm/npm package)
http://micro-os-plus.github.io
MIT License
115 stars 17 forks source link

Allow lambdas with captures as thread functions #65

Open LnnrtS opened 3 years ago

LnnrtS commented 3 years ago

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..

ilg-ul commented 3 years ago

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

LnnrtS commented 3 years ago

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.

ilg-ul commented 3 years ago

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.