From Jason Turner
Watch on YouTube

Summary

In this episode, Jason explores an unusual but interesting aspect of C++ lambdas: manipulating their state's storage duration. He demonstrates how to use static variables within lambdas to create shared state between multiple lambda copies. Then, he illustrates the thread safety issues this approach creates when using lambdas in concurrent environments. Finally, he shows how to use thread_local storage to maintain per-thread state within lambdas, allowing for thread-safe stateful lambdas without locks.

Resources

Tags