Skip to content

Instantly share code, notes, and snippets.

@neunhoef
Created September 11, 2019 13:53
Show Gist options
  • Save neunhoef/09944627a01fe8e52225dc877106e3d8 to your computer and use it in GitHub Desktop.
Save neunhoef/09944627a01fe8e52225dc877106e3d8 to your computer and use it in GitHub Desktop.
// This program exposes a bug. Use alpine Linux and compile as follows:
// g++ exceptioncollision.cpp -o exceptioncollision -O0 -Wall -std=c++14 -lpthread -static
// Then execute the static executable multiple times:
// while true ; do ./exceptioncollision ; date ; done
// after a few tries it will freeze.
#include <thread>
#include <atomic>
#include <chrono>
std::atomic<int> letsgo{0};
void waiter() {
size_t count = 0;
while (letsgo == 0) {
++count;
}
try {
throw 42;
} catch (int const& s) {
}
}
int main(int, char*[]) {
#ifdef REPAIR
try { throw 42; } catch (int const& i) {}
#endif
std::thread t1(waiter);
std::thread t2(waiter);
std::this_thread::sleep_for(std::chrono::milliseconds(10));
letsgo = 1;
t1.join();
t2.join();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment