在哪里' thread_local'变量在内存中创建?

时间:2017-05-12 17:32:28

标签: c++ c++11

在内存中存储thread_local个变量的位置是什么?是heap吗?

我已经为我们的应用程序实现了一个基于每个线程的bootstrap函数,例如:

thread_local bool bootstrapped_ = false;
void Bootstrap()
{
    if (bootstrapped_)
        return;

    thread_local ContextTable contexts;
    contexts_ = &contexts;

    thread_local IndexMapper indexer;
    indexer_ = &indexer;
}

ContextTable* Contexts()
{
    if (!bootstrapped_)
        Bootstrap();
    return contexts_;
}

extern IndexMapper* Indexer()
{
    if (!bootstrapped_)
        Bootstrap();
    return indexer_;
}

在上面的源代码中,分配了变量bootstrapped_contextsindexer的内存在哪里?

0 个答案:

没有答案
相关问题