void getData() { int i; mythread_t tcb; for(i=0; i < MAX_KEYS; i++) { struct threadValues *value = mythread_getspecific(keys[i]); printf("\nmythread_getspecific call for key = %d, values=%d %d\n", keys[i], value->v1, value->v2); if (value == NULL) printf("\nmythread_setspecific call error for thread = %d", keys[i]); tcb = mythread_self(); } }
void *hello(void *t) { ///int *reps = (int*)t; int i = 0; // initialize thread specific data for each thread int* id = (int*)malloc(sizeof(int)); assert(id); *id = mythread_self(); mythread_setspecific(id_key, id); //set name char* name = (char*)malloc(sizeof(char)*MAX_NAME_LENGTH); assert(name); memset(name, '\0', MAX_NAME_LENGTH); sprintf(name, "worker-%d", mythread_self()); mythread_setspecific(name_key,name); // user specific data for (; i < mythread_self(); i++) { printf("Thread-%d:Hello thread:%d\n", mythread_self(), i); sleep(1); mythread_yield(); } printf("Thread specific data for %d thread is %d and worker name is %s\n", mythread_self(), *((int *)mythread_getspecific(id_key)), (char*)mythread_getspecific(name_key)); return NULL; }