Commit 9ef7923e authored by pruthvi's avatar pruthvi

use lock_gaurd to protect the access to m_exec_map in cpu_backend

parent a99d29a0
......@@ -14,6 +14,7 @@
// limitations under the License.
//*****************************************************************************
#include <mutex>
#include <tbb/tbb_stddef.h>
#include "cpu_backend_visibility.h"
......@@ -28,6 +29,10 @@
using namespace ngraph;
using namespace std;
// this mutex will be used to protect the addition and deletion
// of function to m_exec_map across multiple threads
std::mutex exec_map_mutex;
extern "C" runtime::BackendConstructor* get_backend_constructor_pointer()
{
class CPU_BackendConstructor : public runtime::BackendConstructor
......@@ -90,6 +95,7 @@ shared_ptr<runtime::Executable>
ngraph::pass::PassConfig& pass_config,
bool performance_counters_enabled)
{
std::lock_guard<std::mutex> guard(exec_map_mutex);
shared_ptr<runtime::Executable> rc;
auto it = m_exec_map.find(func);
if (it != m_exec_map.end())
......@@ -144,6 +150,7 @@ bool runtime::cpu::CPU_Executable::call(const vector<shared_ptr<runtime::Tensor>
void runtime::cpu::CPU_Backend::remove_compiled_function(shared_ptr<Executable> exec)
{
std::lock_guard<std::mutex> guard(exec_map_mutex);
for (auto it = m_exec_map.begin(); it != m_exec_map.end(); ++it)
{
if (it->second == exec)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment