最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c++ - Why is the getBrowserStoreParams111 Function Initialized Twice in the Same Process and Thread? - Stack Overflow

programmeradmin1浏览0评论

common.h

static int getBrowserStoreParams111(int type);

common

int Common::getBrowserStoreParams111(int type) {
  static int store_param = [type] {
      int result = type;
      std::cout << result << std::endl;
      {
        std::ofstream outfile("D:\\timestamp.log", std::ios::app); // Append mode
        if (outfile.is_open()) {   
          auto now = std::chrono::system_clock::now();
          auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
  
          // Output to file
          outfile << "getBrowserStoreParams111getBrowserStoreParams111getBrowserStoreParams111  timestamp(ms): " << ms << "    common" << "type:" << type << 
          "  current thread ID: " << std::this_thread::get_id() << std::endl;
          outfile.flush();
          outfile.close();
        }
      }
      return result;
  }();
  return store_param;
}

base\commond_line

std::ofstream outfile1("D:\\timestamp.log", std::ios::app);
if (outfile1.is_open()) {   
  auto now = std::chrono::system_clock::now();
  DWORD pid = GetCurrentProcessId(); 
  auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
  
  outfile1 << "begin command_line timestamp(ms) init: " << ms << "  pid:"  << pid 
  << "  current thread ID: " << std::this_thread::get_id()
  << "initinit init:" << base::WideToUTF8(cmd_line) << std::endl;
  outfile1.flush();
  outfile1.close();
}

std::string strHtml = getBrowserStoreParams();
getBrowserStoreParams111(111);
std::ofstream outfile("D:\\timestamp.log", std::ios::app); 
if (outfile.is_open()) {   
  auto now = std::chrono::system_clock::now();
  DWORD pid = GetCurrentProcessId(); 
  auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
  
  outfile << "end command_line timestamp(ms): " << ms << "  pid:" << pid << std::endl;
  outfile.flush();
  outfile.close();
}

log

begin command_line timestamp(ms) init: 1741772439295 pid:21636 current thread ID: 27808 initinit init:out\Release\chrome.exe --token=abcd
getBrowserStoreParams111getBrowserStoreParams111getBrowserStoreParams111 timestamp(ms): 1741772439355 common type: 111 current thread ID: 27808
end command_line timestamp(ms): 1741772439355 pid:21636

begin command_line timestamp(ms) init: 1741772439718 pid:21636 current thread ID: 27808 initinit init:out\Release\chrome.exe --token=abcd
getBrowserStoreParams111getBrowserStoreParams111getBrowserStoreParams111 timestamp(ms): 1741772439731 common type: 111 current thread ID: 27808
end command_line timestamp(ms): 1741772439731 pid:21636

The logs show that the getBrowserStoreParams111 function is being initialized twice in the same process and thread.

The static variable store_param in the file command_line is initialized twice, but I am certain it's the same process and thread. I'm not sure why this happens in Release mode, but it works fine in Debug mode. I am working on a custom version of Chromium.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论