[PATCH 06/15] nptl: Use exit_lock when accessing TID on pthread_getaffinity_np
Adhemerval Zanella
adhemerval.zanella@linaro.org
Tue Oct 5 13:47:53 GMT 2021
On 05/10/2021 04:35, Cyril Hrubis wrote:
> Hi!
>>>> The RATIONALE for most pthread_{get,set}sched*() functions has:
>>>>
>>>> If an implementation detects use of a thread ID after the end of its
>>>> lifetime, it is recommended that the function should fail and report an
>>>> [ESRCH] error.
>>>>
>>>> See for example:
>>>>
>>>> https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/
>>>
>>> Exactly. If the thread has exited, but is still joinable, the thread
>>> ID lifetime has not ended, so we should not return ESRCH.
>>>
>>
>> But in this case the information can not be queried from the kernel,
>> any information that glibc returns will not make sense (even an
>> empty affinity mask). We can try to cache the pthread_setaffinity_np()
>> value, but I really want to avoid such complexity and the extra space
>> required in struct pthread.
>>
>> I think this is QoI to indicate the caller such information can not
>> be obtained, instead of returning an bogus value.
>
> I guess that if we want to return an error it should be something
> different from ESRCH in order not to confuse, however there does not
> seem to be a good match for this condition as far as I can tell.
>
Maybe return EINVAL then, but returning an failure would still tie
its semantic to check for pthread_t validity. So the question is
whether would be better to no tie the pthread_setaffinity_np() (or
any other interface that requires the pthread tid valid value)
to check for pthread lifetime and return a bogus value (with possible
side-effects) or return an error to make it clear to caller.
More information about the Libc-alpha
mailing list