Skip to content

Commit b9bc25c

Browse files
committed
fix issue #861
1 parent 83c36a4 commit b9bc25c

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/tree_node.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "behaviortree_cpp/tree_node.h"
1515

1616
#include <array>
17+
#include <atomic>
1718
#include <cstring>
1819

1920
namespace BT
@@ -104,8 +105,12 @@ NodeStatus TreeNode::executeTick()
104105
if(!substituted)
105106
{
106107
using namespace std::chrono;
108+
// Use atomic_thread_fence to prevent compiler reordering of time measurements.
109+
// See issue #861 for details.
107110
const auto t1 = steady_clock::now();
111+
std::atomic_thread_fence(std::memory_order_seq_cst);
108112
new_status = tick();
113+
std::atomic_thread_fence(std::memory_order_seq_cst);
109114
const auto t2 = steady_clock::now();
110115
if(monitor_tick)
111116
{

0 commit comments

Comments
 (0)