3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-08 18:31:49 +00:00

Multi-threading bugfix, DLL could be used from other threads before the main thread initializes it.

Thanks to user xor88 for reporting this one.

Signed-off-by: Christoph M. Wintersteiger <cwinter@microsoft.com>
This commit is contained in:
Christoph M. Wintersteiger 2014-09-03 17:49:10 +01:00
parent fa24d9db6f
commit 23af977d68

View file

@ -35,6 +35,7 @@ static long long g_memory_max_used_size = 0;
static long long g_memory_watermark = 0;
static bool g_exit_when_out_of_memory = false;
static char const * g_out_of_memory_msg = "ERROR: out of memory";
static volatile bool g_memory_fully_initialized = false;
void memory::exit_when_out_of_memory(bool flag, char const * msg) {
g_exit_when_out_of_memory = flag;
@ -83,10 +84,18 @@ void memory::initialize(size_t max_size) {
initialize = true;
}
}
if (!initialize)
return;
g_memory_out_of_memory = false;
mem_initialize();
if (initialize) {
g_memory_out_of_memory = false;
mem_initialize();
g_memory_fully_initialized = true;
}
else {
// Delay the current thread until the DLL is fully initialized
// Without this, multiple threads can start to call API functions
// before memory::initialize(...) finishes.
while (!g_memory_fully_initialized)
/* wait */ ;
}
}
bool memory::is_out_of_memory() {
@ -98,9 +107,9 @@ bool memory::is_out_of_memory() {
return r;
}
void memory::set_high_watermark(size_t watermak) {
void memory::set_high_watermark(size_t watermark) {
// This method is only safe to invoke at initialization time, that is, before the threads are created.
g_memory_watermark = watermak;
g_memory_watermark = watermark;
}
bool memory::above_high_watermark() {