码迷,mamicode.com
首页 > 编程语言 > 详细

线程变量

时间:2017-05-21 00:20:57      阅读:295      评论:0      收藏:0      [点我收藏+]

标签:elf   return   logs   bsp   cal   ret   exit   lob   global   

 

__thread int my_var = 6;

#if T_DESC("global", 1)
pid_t gettid(void)
{  
    return syscall(SYS_gettid);  
} 
#endif

#if T_DESC("TU1", 1)
void thread_1(void)  
{  
    int i;  

    for(i=0; i<10; i++)  {
        printf("thread_1: pid=0x%x tid=0x%x self=0x%x\n", getpid(), gettid(), (int)pthread_self());
        my_var += 2;
        printf("thread_1: my_var=%d addr=0x%x \n", my_var, &my_var);
        sleep(1);  
    }  
    pthread_exit(0);  
}  
  
void thread_2(void)  
{  
    int i;  
    
    for(i=0; i<5; i++) {
        printf("thread_2: pid=0x%x tid=0x%x self=0x%x\n", getpid(), gettid(), (int)pthread_self());
        my_var += 3;
        printf("thread_2: my_var=%d addr=0x%x \n", my_var, &my_var);
        sleep(1);  
    }  
    pthread_exit(0);  
}  

thread_2: pid=0x741 tid=0x743 self=0x85254700
thread_2: my_var=9 addr=0x852546fc
thread_1: pid=0x741 tid=0x742 self=0x85a55700
thread_1: my_var=8 addr=0x85a556fc
thread_2: pid=0x741 tid=0x743 self=0x85254700
thread_2: my_var=12 addr=0x852546fc
thread_1: pid=0x741 tid=0x742 self=0x85a55700
thread_1: my_var=10 addr=0x85a556fc
thread_2: pid=0x741 tid=0x743 self=0x85254700
thread_2: my_var=15 addr=0x852546fc

 

 

线程变量

标签:elf   return   logs   bsp   cal   ret   exit   lob   global   

原文地址:http://www.cnblogs.com/soul-stone/p/6883530.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!