title: How to get value of atomic variable outside the thread in C++
body: <p>I have a thread, which keeps running, and this thread receives data from udp network.
  when there is no data coming in for lets say 3 seconds, i am setting a atomic variable[STATUS] as 0 and if data started coming again setting atomic variable[STATUS] value is 1</p>
  <p>code below:</p>
  <pre><code>ProtoApiManager.hpp
  ------------------
  // to update computer status
  atomic_int STATUS = ATOMIC_VAR_INIT(0);
  
  ProtoApiManager.cpp
  ------------------
  _keep_running = true;
  _t_bg_tasks = std::thread(&amp;ProtoApiManager::onThreadBgTasks, this);
  void main::onThreadBgTasks()
  {
      do
      {
          milliseconds currentTime = MiscUtils::getTimeNow();// getting current time
          auto delta = currentTime - _last_status_msg_rx; // assigned when data received
           if (delta.count() &gt; _NAV_COMMS_TIMEOUT) // constant assigned as 3 sec
          {
              std::cout&lt;&lt;&quot;Time out OFFLINE&quot;&lt;&lt;std::endl;
              
              MC_COMPUTER_STATUS = 0;
              // prepareData()
              
          }else{
  
              std::cout&lt;&lt;&quot;Time out ONLINE&quot;&lt;&lt;std::endl;
              MC_COMPUTER_STATUS = 1;
              // prepareData()
             }
  
      }
      while(_keep_running);
  }
  
  ---------------
  ProtoApiManager.process.cpp
  ---------------------------
  ProtoApiManager::prepareData()
  {
    // preparing data
      hardwareItemStatusMCComputer-&gt;set_hardwaretype(10);
      hardwareItemStatusMCComputer-&gt;set_hardwarename(&quot;MC Computer&quot;);
      hardwareItemStatusMCComputer-&gt;set_hardwarestatus(STATUS);
  
    // transmitting to udp
  }
  ---------------------------
  </code></pre>
  <p>Now the question is, as thread is keep running in do while, and based on time out i set atomic variable value 0 or 1, i have to call prepareData method outside thread based on atomic variable[STATUS] and set [status] while preparing data</p>