Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow lambdas with captures as thread functions #65

Open
LnnrtS opened this issue Jan 6, 2021 · 3 comments
Open

Allow lambdas with captures as thread functions #65

LnnrtS opened this issue Jan 6, 2021 · 3 comments

Comments

@LnnrtS
Copy link
Contributor

LnnrtS commented Jan 6, 2021

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
Copy link
Contributor

ilg-ul commented Jan 6, 2021

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

@LnnrtS
Copy link
Contributor Author

LnnrtS commented Jan 6, 2021

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
Copy link
Contributor

ilg-ul commented Jan 6, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants