如何使C中的胎面本地存储在C中
static __thread vars* ptr=NULL;
void thread_init(vars* new_vars){
if(new_vars){
ptr=new_vars
}
printf("%p",ptr);
}
__ thread是GCC的扩展
线程1是主线程的一个线程
1_CHILD是thread1 thread1
call thread_init(a)in main // ptr是a,而不是null
call thread_init(b)thread1 // prthe1 // ptr中的ptr是b,而不是null
call thread_init(null)(null)(null)在thread1_child // ptr为null,而不是b
如何动态初始化 (thread1 == thread1_child的ptr)?
static __thread vars* ptr=NULL;
void thread_init(vars* new_vars){
if(new_vars){
ptr=new_vars
}
printf("%p",ptr);
}
__thread is GCC's extention
thread1 is one thread of main
thread1_child is child of thread1
call thread_init(a) in main //ptr is a, not NULL
call thread_init(b) in thread1 //ptr is b, not NULL
call thread_init(NULL) in thread1_child //ptr is NULL,not b
how to dynamically initialize
(ptr of thread1 == ptr of thread1_child) ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论