[PATCH v2 10/19] nptl: Use tidlock when accessing TID on pthread_getaffinity_np
Florian Weimer
fweimer@redhat.com
Mon Aug 30 09:30:56 GMT 2021
* Adhemerval Zanella:
>> The pthread_cancel reference looks like a cut-and-paste-bug.
>
> It is, but I think it is applicable. Maybe:
>
> /* Block all signal, since the lock is not recursive and used on
> async-signal-safe functions. */
Just mention async-signal-safe, please. I do not think recursive locks
can achieve async-signal-safety.
>>> + sigset_t oldmask;
>>> + __libc_signal_block_all (&oldmask);
>>> + lll_lock (pd->tidlock, LLL_PRIVATE);
>>> +
>>> + int res = pd->tid == 0
>>> + ? -ESRCH
>>> + : INTERNAL_SYSCALL_CALL (sched_getaffinity, pd->tid,
>>> + MIN (INT_MAX, cpusetsize), cpuset);
>>> +
>>> + lll_unlock (pd->tidlock, LLL_PRIVATE);
>>> + __libc_signal_restore_set (&oldmask);
>>> +
>>> + if (res < 0)
>>> + return -res;
>>
>> ESRCH doesn't look like the right error code here. Should we return an
>> affinity mask without any bits set?
>
> Why not? Returning anything but an error does not improve things here
> since the information won't make much sense. Also it follows what other
> symbols is already doing (such as pthread_cancel()).
POSIX reserves ESRCH for using a pthread_t thread ID outside of the
thread lifetime. In glibc, this is always undefined. In contrast, the
case above involves a valid thread ID of a thread that has exited.
Returning ESRCH suggests that the thread lifetime has ended, which is
not true.
Thanks,
Florian
More information about the Libc-alpha
mailing list