From 6c67cb5baa845920cc2dabe90c52a39529f41494 Mon Sep 17 00:00:00 2001 From: Yifan Zhao <yifanz16@illinois.edu> Date: Thu, 16 Jan 2020 15:44:31 -0600 Subject: [PATCH] Fixed race condition in visc-rt --- hpvm/projects/visc-rt/visc-rt.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/hpvm/projects/visc-rt/visc-rt.cpp b/hpvm/projects/visc-rt/visc-rt.cpp index c5ce64dc4b..e4fddca19e 100644 --- a/hpvm/projects/visc-rt/visc-rt.cpp +++ b/hpvm/projects/visc-rt/visc-rt.cpp @@ -122,28 +122,38 @@ void llvm_visc_x86_dstack_push(unsigned n, uint64_t limitX, uint64_t iX, uint64_ DEBUG(cout << "\tNumDim = " << n << "\t Limit(" << limitX << ", " << limitY << ", "<< limitZ <<")\n"); DEBUG(cout << "\tInstance(" << iX << ", " << iY << ", "<< iZ <<")\n"); DFGDepth nodeInfo (n, limitX, iX, limitY, iY, limitZ, iZ); + pthread_mutex_lock(&ocl_mtx); DStack.push_back(nodeInfo); DEBUG(cout << "DStack size = " << DStack.size() << flush << "\n"); + pthread_mutex_unlock(&ocl_mtx); } void llvm_visc_x86_dstack_pop() { DEBUG(cout << "Popping from depth stack\n"); + pthread_mutex_lock(&ocl_mtx); DStack.pop_back(); DEBUG(cout << "DStack size = " << DStack.size() << flush << "\n"); + pthread_mutex_unlock(&ocl_mtx); } uint64_t llvm_visc_x86_getDimLimit(unsigned level, unsigned dim) { DEBUG(cout << "Request limit for dim " << dim << " of ancestor " << level <<flush << "\n"); + pthread_mutex_lock(&ocl_mtx); unsigned size = DStack.size(); DEBUG(cout << "\t Return: " << DStack[size-level-1].getDimLimit(dim) <<flush << "\n"); - return DStack[size-level-1].getDimLimit(dim); + uint64_t result = DStack[size-level-1].getDimLimit(dim); + pthread_mutex_unlock(&ocl_mtx); + return result; } uint64_t llvm_visc_x86_getDimInstance(unsigned level, unsigned dim) { DEBUG(cout << "Request instance id for dim " << dim << " of ancestor " << level <<flush << "\n"); + pthread_mutex_lock(&ocl_mtx); unsigned size = DStack.size(); DEBUG(cout << "\t Return: " << DStack[size-level-1].getDimInstance(dim) <<flush << "\n"); - return DStack[size-level-1].getDimInstance(dim); + uint64_t result = DStack[size-level-1].getDimInstance(dim); + pthread_mutex_unlock(&ocl_mtx); + return result; } /********************** Memory Tracking Routines **************************/ -- GitLab