Skip to content

Commit

Permalink
Fixing concurrency handler static global variable
Browse files Browse the repository at this point in the history
  • Loading branch information
khuck committed Apr 2, 2021
1 parent f84fc56 commit 6a945ac
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/apex/concurrency_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@

using namespace std;

std::vector<std::mutex*> _per_thread_mutex;
std::vector<std::mutex*>& _per_thread_mutex() {
static std::vector<std::mutex*> ptm;
return ptm;
}

namespace apex {

Expand All @@ -56,9 +59,10 @@ concurrency_handler::~concurrency_handler () {
for (auto tmp : _event_stack) {
delete(tmp);
}
for (auto tmp : _per_thread_mutex) {
delete(tmp);
}
// for some reason this causes shutdown crashes
// for (auto tmp : _per_thread_mutex()) {
// delete(tmp);
// }
for (auto tmp : _states) {
delete(tmp);
}
Expand Down Expand Up @@ -95,7 +99,7 @@ bool concurrency_handler::_handler(void) {
task_identifier func;
if (tmp != nullptr && tmp->size() > 0) {
{
std::lock_guard<std::mutex> l(*_per_thread_mutex[i]);
std::lock_guard<std::mutex> l(*(_per_thread_mutex()[i]));
if (tmp->size() > 0) {
func = tmp->top();
} else {
Expand Down Expand Up @@ -143,7 +147,7 @@ bool concurrency_handler::common_start(task_identifier *id) {
if (!_terminate) {
int i = thread_instance::get_id();
stack<task_identifier>* my_stack = get_event_stack(i);
std::lock_guard<std::mutex> l(*_per_thread_mutex[i]);
std::lock_guard<std::mutex> l(*(_per_thread_mutex()[i]));
my_stack->push(*id);
return true;
} else {
Expand All @@ -163,7 +167,7 @@ void concurrency_handler::common_stop(std::shared_ptr<profiler> &p) {
if (!_terminate) {
int i = thread_instance::get_id();
stack<task_identifier>* my_stack = get_event_stack(i);
std::lock_guard<std::mutex> l(*_per_thread_mutex[i]);
std::lock_guard<std::mutex> l(*(_per_thread_mutex()[i]));
if (!my_stack->empty()) {
my_stack->pop();
}
Expand Down Expand Up @@ -226,7 +230,7 @@ inline void concurrency_handler::add_thread(unsigned int tid) {
std::lock_guard<std::mutex> l(_vector_mutex);
while(_event_stack.size() <= tid) {
_event_stack.push_back(new stack<task_identifier>);
_per_thread_mutex.push_back(new std::mutex());
_per_thread_mutex().push_back(new std::mutex());
}
_stack_count = _event_stack.size();
}
Expand Down

0 comments on commit 6a945ac

Please sign in to comment.