Guest User

Untitled

a guest
Aug 17th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. Using available physical CPU core in pthread in Linux
  2. thread1 in proccessor 0
  3. thread2 in proccessor 1
  4. .
  5. .
  6. .
  7. threadn in processor n
  8.  
  9. if(for thread 1 )
  10. {
  11. pthread_attr_init(&pta);
  12. CPU_SET(0,&cpuset);
  13. pthread_setaffinity_np(thread1, sizeof(cpu_set_t), &cpuset);
  14. pthread_create(&thread1,&pta,&sendimsg,(void*)&message);
  15. pthread_join(thread1,NULL);
  16. printf("User for Thread One : %dn",numb.fir);
  17. pthread_attr_destroy(&pta);
  18. CPU_ZERO(&cpuset);
  19. }
  20.  
  21. else if(for thread 2)
  22. {
  23. pthread_attr_init(&pra);
  24. CPU_SET(1,&cpuset1);
  25. pthread_setaffinity_np(thread2, sizeof(cpu_set_t), &cpuset);
  26. pthread_create(&thread2,&pra,&sendimsg,(void*)&message);
  27. pthread_join(thread2,NULL);
  28. printf("User for Thread Two : %dn",numb.sec);
  29. pthread_attr_destroy(&pra);
  30. CPU_ZERO(&cpuset1);
  31. }
  32.  
  33. for eight thread that way.
Add Comment
Please, Sign In to add comment