I recently started using lambdas very much in streams, and want to make sure that I don't tune into security / crash issues later. My usual way to use them:
class SomeClass {
int someid;
void NextCommand();
std::function<void(int, int)> StoreNumbers;
SomeClass(id, fn);
}
static void read_callback(int fd, void* ptr)
{
SomeClass* sc = static_cast<SomeClass*>ptr;
..
sc->StoreNumbers(someint,someotherint);
}
static DWORD WINAPI ThreadFn(LPVOID param)
{
std::list<int> ints1;
std::list<int> ints2;
auto storenumbers = [&] (int i, int i2) {
ints1.push_back(i);
ints2.push_back(i2);
};
SomeClass s(id, storenumbers);
...
}
ThreadFn is used as a thread function for 30-40 threads.
It is acceptable? Usually I have a few of these stream specific lambdas that work with a bunch of specific stream data.
Thank!
source
share