3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-02-28 19:01:29 +00:00
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2019-06-03 19:50:25 -07:00 committed by Nuno Lopes
parent 2788f72bbb
commit 9262908ebb
30 changed files with 191 additions and 341 deletions

View file

@ -17,24 +17,20 @@ Notes:
--*/
#ifndef _NO_OMP_
#include "util/cooperate.h"
#include "util/trace.h"
#include "util/debug.h"
#include "util/z3_omp.h"
#include <thread>
#include <mutex>
struct cooperation_lock {
omp_nest_lock_t m_lock;
std::recursive_mutex m_lock;
char const * m_task;
volatile int m_owner_thread;
std::thread::id m_owner_thread;
cooperation_lock() {
omp_set_nested(1);
omp_init_nest_lock(&m_lock);
m_task = nullptr;
m_owner_thread = -1;
}
~cooperation_lock() {
omp_destroy_nest_lock(&m_lock);
}
};
@ -45,20 +41,18 @@ bool cooperation_ctx::g_cooperate = false;
void cooperation_ctx::checkpoint(char const * task) {
SASSERT(cooperation_ctx::enabled());
int tid = omp_get_thread_num();
std::thread::id tid = std::this_thread::get_id();
if (g_lock.m_owner_thread == tid) {
g_lock.m_owner_thread = -1;
omp_unset_nest_lock(&(g_lock.m_lock));
g_lock.m_owner_thread = std::thread::id();
g_lock.m_lock.unlock();
}
// this critical section is used to force the owner thread to give a chance to
// another thread to get the lock
#pragma omp critical (z3_cooperate)
{
omp_set_nest_lock(&(g_lock.m_lock));
TRACE("cooperate_detail", tout << task << ", tid: " << tid << "\n";);
CTRACE("cooperate", g_lock.m_task != task, tout << "moving to task: " << task << "\n";);
g_lock.m_owner_thread = tid;
}
std::this_thread::yield();
g_lock.m_lock.lock();
TRACE("cooperate_detail", tout << task << ", tid: " << tid << "\n";);
CTRACE("cooperate", g_lock.m_task != task, tout << "moving to task: " << task << "\n";);
g_lock.m_owner_thread = tid;
}
#endif