Skip to content

Instantly share code, notes, and snippets.

@root42
Created November 14, 2019 12:05
Show Gist options
  • Save root42/580137970bc36e1e12b20c6ee24c5f69 to your computer and use it in GitHub Desktop.
Save root42/580137970bc36e1e12b20c6ee24c5f69 to your computer and use it in GitHub Desktop.
How to crash a thread with a shared_ptr reference
#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