Stupid C++ Threads and Lambdas

For a unit test that I’m writing for some code at the moment, I need to create a thread that doesn’t do anything. Well, the easiest way to do this is to do a lambda function. And since we don’t need to capture anything, and the thread doesn’t need to do anything, I have written the following line of code:

std::thread thr = std::thread( [](){} );

Just look at it in its simplicity. In case you missed it:

[](){}

I actually started laughing after I had written that, it’s just so stupid that it’s funny!

One thought on “Stupid C++ Threads and Lambdas

Leave a Reply

Your email address will not be published. Required fields are marked *