Last active
August 18, 2018 06:20
Demo of thread reclamation crashes w/o hooking world/Del
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 <thread> | |
#include <memory> | |
#include <atomic> | |
using namespace std; | |
using namespace std::chrono_literals; | |
atomic<bool> should_quit; | |
struct wrapper { | |
thread th; | |
wrapper(thread&& th) : th(move(th)) {} | |
~wrapper() { should_quit.store(true); th.join(); } | |
}; | |
unique_ptr<wrapper> handle; | |
atomic<int> message; | |
extern "C" const char* start() { | |
handle = make_unique<wrapper>(thread([](){ | |
for (int i = 1; i < 10; ++i) { | |
message.store(i); | |
this_thread::sleep_for(1s); | |
if (should_quit.load()) { | |
return; | |
} | |
} | |
message.store(-1); | |
})); | |
return ""; | |
} | |
extern "C" const char* update() { | |
static char buf[128]; | |
int msg = message.load(); | |
if (msg == 0) { | |
return "..."; | |
} else if (msg == -1) { | |
return ""; | |
} else { | |
message.store(0); | |
sprintf(buf, "%d", msg); | |
return buf; | |
} | |
} | |
extern "C" const char* stop() { | |
handle.reset(); | |
return ""; | |
} |
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
#define DLL @"test.dll" | |
/client/verb/Go() | |
src << "starting" | |
call(DLL, "start")() | |
var/r | |
while ((r = call(DLL, "update")())) | |
if (r != "...") | |
src << "progress: [r]" | |
sleep (1) | |
src << "done" | |
/client/verb/Reboot_Badly() | |
world.Reboot() | |
/client/verb/Reboot_Safely() | |
call(DLL, "stop")() | |
world.Reboot() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment