I am trying to see how a lambda function along with std::function
can be used in a program where different child processes are created and sharing contents of lambda. I have code something like which is to be used among different with child process created from parent process fork.
struct Foo {
std::function<void()> bar;
};
void some_func(void *a, void *b)
{
}
int main()
{
void *a, *b;
auto func= [=]() {
some_func(a, b);
};
Foo f{func};
}
I see some problems accessing this allocation across different processes. From what I have read on this forum about lambda expression and std::function
can allocate space on heap. Probably when value capture list in the list grows it would not be just a stack object and hence it could not not be properly shared among the processes. I came across boost::interprocess
library which allows to use allocators in multi process environment for sharing for containers like vector etc. Unfortunately as I understand allocators for std::function have been deprecated since C++17. So what are the alternatives to use have lambda expression as above in multi process environment when data is supposed to be shared?