Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Using available physical CPU core in pthread in Linux
- thread1 in proccessor 0
- thread2 in proccessor 1
- .
- .
- .
- threadn in processor n
- if(for thread 1 )
- {
- pthread_attr_init(&pta);
- CPU_SET(0,&cpuset);
- pthread_setaffinity_np(thread1, sizeof(cpu_set_t), &cpuset);
- pthread_create(&thread1,&pta,&sendimsg,(void*)&message);
- pthread_join(thread1,NULL);
- printf("User for Thread One : %dn",numb.fir);
- pthread_attr_destroy(&pta);
- CPU_ZERO(&cpuset);
- }
- else if(for thread 2)
- {
- pthread_attr_init(&pra);
- CPU_SET(1,&cpuset1);
- pthread_setaffinity_np(thread2, sizeof(cpu_set_t), &cpuset);
- pthread_create(&thread2,&pra,&sendimsg,(void*)&message);
- pthread_join(thread2,NULL);
- printf("User for Thread Two : %dn",numb.sec);
- pthread_attr_destroy(&pra);
- CPU_ZERO(&cpuset1);
- }
- for eight thread that way.
Add Comment
Please, Sign In to add comment