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

Viewed 25365

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 id using pthread_self()

    Set CPU affinity using pthread_setaffinity_np(....) by passing the thread id as an argument

  2. Get thread id using the gettid() call

    Set CPU affinity using sched_setaffinity(....) by passing the thread id in the place of the process id

P.S: After setting the CPU affinity, I intend to increase the scheduling priority of the thread.

2 Answers
Related