【问题标题】:Thread local storage constructor g++线程本地存储构造函数 g++
【发布时间】:2016-04-26 18:28:21
【问题描述】:

由于非平凡的线程本地存储变量有开销,我想在某些函数上使用__attribute__((constructor)) 指示来初始化线程本地数据(旨在每次线程启动时都会调用该函数)。 这怎么可能?

【问题讨论】:

    标签: c++ multithreading g++ thread-local


    【解决方案1】:

    您不能以这种方式使用__attribute__((constructor))。没有选项可以指定每次新线程启动时由 TLS 自动调用的函数。您将不得不使用 lazy initialization 手动对其进行编码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多