What is the difference between pthread_self() and gettid()? Which one should I use?

后端 未结 2 880
借酒劲吻你
借酒劲吻你 2020-12-08 11:05

I\'m trying to set the CPU affinity of threads on Linux. I\'d like to know which one of the following approaches is recommended:

  1. Get thread

2条回答
  •  甜味超标
    2020-12-08 11:29

    I believe the fact that gettid() exists only as a system call and hasn't been exposed directly as an API call could mean "use it only if you're absolutely certain of what you're doing" and gettid() is not meant to be portable.

    You should be better if you stick to pthread. You can change scheduling policy/priority later with pthread_setschedparam()

提交回复
热议问题