Skip to content

Instantly share code, notes, and snippets.

@toddlipcon
Created December 19, 2016 14:06
Show Gist options
  • Save toddlipcon/c4d8b263ef2ee2f360c8ec1db3e33263 to your computer and use it in GitHub Desktop.
Save toddlipcon/c4d8b263ef2ee2f360c8ec1db3e33263 to your computer and use it in GitHub Desktop.
#include <sanitizer/lsan_interface.h>
#include <thread>
#include <unistd.h>
#include <pthread.h>
#include <deque>
#include <iostream>
using namespace std;
pthread_key_t g_key;
void CreateThreads() {
deque<thread> threads;
while (true) {
while (threads.size() > 100) {
threads.front().join();
threads.pop_front();
}
threads.emplace_back([&]() {
if (pthread_setspecific(g_key, malloc(10)) != 0) {
perror("could not set val");
exit(1);
}
});
}
}
int main() {
pthread_key_create(&g_key, free);
thread thread_creator(CreateThreads);
while (true) {
if (__lsan_do_recoverable_leak_check()) {
cerr << "leaks!\n";
} else {
cerr << ".";
}
usleep(10000);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment