本文整理汇总了C++中ThreadLocal::value方法的典型用法代码示例。如果您正苦于以下问题:C++ ThreadLocal::value方法的具体用法?C++ ThreadLocal::value怎么用?C++ ThreadLocal::value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ThreadLocal
的用法示例。
在下文中一共展示了ThreadLocal::value方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
Thread p(bind(&thr_fn), "thread1");
cout << "tid:" << CurrentThread::tid() <<" name:" << CurrentThread::name() << endl;
int ret = p.start();
if(ret < 0)
{
printf("p start error\n");
assert(0);
}
obj.value().set_name("main one");
cout << "main set instance name:" << obj.value().name() << endl;
ret = p.join();
if(ret < 0)
{
perror("p join error:");
assert(0);
}
cout << "finnally main name:" <<obj.value().name() << endl;
return 0;
}
示例2: thr_fn
void thr_fn()
{
cout << "tid:" << CurrentThread::tid() <<" name:" << CurrentThread::name() << endl;
sleep(1);
cout << "thread first read name:" << obj.value().name() << endl;
obj.value().set_name("thread one");
cout << "thread set read name:" << obj.value().name() << endl;
sleep(2);
return ;
}
示例3: snprintf
const string& Thread::getTidString()
{
if (t_tidstring.value().empty())
{
Thread::ThreadHandle ret_tid;
ret_tid = ::pthread_self();
t_tid.value() = ret_tid;
char buf[32] = {0};
snprintf(buf, sizeof(buf), "%ll", (uint64_t)ret_tid);
t_tidstring.value() = buf;
}
return t_tidstring;
}
示例4: getCurrentThreadID
Thread::ThreadHandle Thread::getCurrentThreadID()
{
getTidString();
return t_tid.value();
}