标签:code word 起源 org 连接器 大量 机制 系统 file
__thread int i; extern __thread struct state s; static __thread char *p;这个keyword__thread能够单独使用。也能够和extern或者static配合使用,不能与其它的存储类说明符使用。当使用extern或者static。__thread必须在这些存储keyword后面使用。
/*File : thread.c *Auth : sjin *Date : 20141023 *Mail : 413977243@qq.com */ #include <stdio.h> #include <pthread.h> #define MAX_THREADS 2 static __thread int i = 1; void *thr_func(void *arg) { printf("pself = %d,i = %d\n",pthread_self(),i); i = ( int)pthread_self(); printf("pself = %d,i = %d\n",pthread_self(),i); } int main() { int j = 0; pthread_t thread_id[MAX_THREADS]; for(j = 0; j < MAX_THREADS;j++){ pthread_create(&thread_id[j],0,thr_func,NULL); } for(j = 0; j < MAX_THREADS;j++){ pthread_join(thread_id[j],NULL); } return 0; }执行结果:
pself = -1218581696,i = 1 pself = -1218581696,i = -1218581696 pself = -1226974400,i = 1 pself = -1226974400,i = -1226974400
标签:code word 起源 org 连接器 大量 机制 系统 file
原文地址:http://www.cnblogs.com/gccbuaa/p/6718491.html