pthread не дает вам понять? - PullRequest
1 голос
/ 08 мая 2020

В Linux tid извлекается с помощью системного вызова: gettid().

Объект pthread хранит tid в struct pthread:

struct pthread {
...

  /* This descriptor's link on the `stack_used' or `__stack_user' list.  */
  list_t list;

  /* Thread ID - which is also a 'is this thread descriptor (and
     therefore stack) used' flag.  */
  pid_t tid;

  /* Ununsed.  */
  pid_t pid_ununsed;
...
};

Я считаю, что эта структура хранится в основании стека? Во всяком случае, каждый pthread имеет к нему доступ. Например, в реализации pthread_create он захватывает структуру pthread:

struct pthread *self = THREAD_SELF;

Итак, мой вопрос: почему нет вызова pthread_gettid_np()? Может быть, gettid() настолько быстр, что его можно пренебречь? А может, звонок есть, и я просто нигде не могу его найти?

...