Created
November 14, 2019 12:05
-
-
Save root42/580137970bc36e1e12b20c6ee24c5f69 to your computer and use it in GitHub Desktop.
How to crash a thread with a shared_ptr reference
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <memory> | |
#include <iostream> | |
#include <thread> | |
int main() | |
{ | |
std::shared_ptr<std::thread> mythread; | |
mythread.reset( | |
new std::thread( | |
[&]() { | |
std::cout << "Thread here!" << std::endl; | |
#ifdef DO_CRASH | |
mythread.reset(); | |
#endif | |
} | |
) | |
); | |
std::cout << "Main function" << std::endl; | |
#ifndef DO_CRASH | |
mythread->join(); | |
mythread.reset(); | |
#endif | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment