Commit 9657490e authored by Robert Kimball's avatar Robert Kimball Committed by Adam Procter

make static 'next item' counters thread safe by making them atomic (#186)

parent 2d05276d
......@@ -20,7 +20,7 @@
using namespace std;
using namespace ngraph;
size_t Function::m_next_instance_id = 0;
atomic<size_t> Function::m_next_instance_id(0);
Function::Function(const std::shared_ptr<Node>& result,
const std::shared_ptr<ValueType>& result_type,
......@@ -31,7 +31,7 @@ Function::Function(const std::shared_ptr<Node>& result,
, m_name(name)
, m_result_type(result_type)
, m_ordered_ops_valid(false)
, m_instance_id(m_next_instance_id++)
, m_instance_id(m_next_instance_id.fetch_add(1))
{
size_t i = 0;
for (auto parameter : parameters)
......
......@@ -14,6 +14,7 @@
#pragma once
#include <atomic>
#include <initializer_list>
#include <list>
#include <memory>
......@@ -68,7 +69,7 @@ namespace ngraph
Function(const Function&) = delete;
Function(const Function&&) = delete;
static size_t m_next_instance_id;
static std::atomic<size_t> m_next_instance_id;
size_t m_instance_id;
};
}
......@@ -17,12 +17,12 @@
using namespace std;
using namespace ngraph;
size_t Node::m_next_instance_id = 0;
atomic<size_t> Node::m_next_instance_id(0);
Node::Node(const std::vector<shared_ptr<Node>>& arguments, shared_ptr<ValueType> value_type)
: m_arguments(arguments)
, m_value_type(value_type)
, m_instance_id(m_next_instance_id++)
, m_instance_id(m_next_instance_id.fetch_add(1))
, m_is_output(false)
{
// Add this node as a user of each argument.
......
......@@ -14,6 +14,7 @@
#pragma once
#include <atomic>
#include <set>
#include <string>
#include <unordered_set>
......@@ -114,7 +115,7 @@ namespace ngraph
std::multiset<Node*> m_users;
std::string m_name;
size_t m_instance_id;
static size_t m_next_instance_id;
static std::atomic<size_t> m_next_instance_id;
std::deque<descriptor::Input> m_inputs;
std::deque<descriptor::Output> m_outputs;
bool m_is_output;
......
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