Skip to content

Commit

Permalink
[bug] Add a mutex to protect counters_map in Statistics (#6645)
Browse files Browse the repository at this point in the history
Issue: fixes #6644

### Brief Summary
  • Loading branch information
lin-hitonami authored Nov 18, 2022
1 parent bc08773 commit 559097a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions taichi/util/statistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace taichi {
Statistics stat;

void Statistics::add(std::string key, Statistics::value_type value) {
std::lock_guard<std::mutex> _(counters_map_mutex_);
counters_[key] += value;
}

Expand Down
2 changes: 2 additions & 0 deletions taichi/util/statistics.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <unordered_map>
#include <mutex>

#include "taichi/common/core.h"

Expand All @@ -23,6 +24,7 @@ class Statistics {

private:
counters_map counters_;
std::mutex counters_map_mutex_;
};

extern Statistics stat;
Expand Down

0 comments on commit 559097a

Please sign in to comment.