[vlc-devel] [PATCH v3 1/4] thread: add a function to give names to threads

Steve Lhomme robux4 at ycbcr.xyz
Thu Nov 12 07:23:33 CET 2020


On 2020-11-11 18:56, Rémi Denis-Courmont wrote:
> Le tiistaina 10. marraskuuta 2020, 13.05.47 EET Steve Lhomme a écrit :
>> Given the amount of threads used by VLC it can be useful to known which
>> thread is what when debugging or in a backtrace (especially if the stack is
>> bogus, we can get a hint at where the thread comes from).
>>
>> This feature is supported in the Windows debugger when used on Windows 10
>> 1607 and upper. There might be support in gdb on other platforms as well.
>>
>> The posix variants comes from dav1d.
>> ---
>>   include/vlc_threads.h | 10 ++++++++++
>>   src/android/thread.c  |  8 ++++++++
>>   src/libvlccore.sym    |  1 +
>>   src/os2/thread.c      |  5 +++++
>>   src/posix/thread.c    | 23 +++++++++++++++++++++++
>>   src/win32/thread.c    | 21 +++++++++++++++++++++
>>   6 files changed, 68 insertions(+)
>>
>> diff --git a/include/vlc_threads.h b/include/vlc_threads.h
>> index 21f4e46c278..46490334eb8 100644
>> --- a/include/vlc_threads.h
>> +++ b/include/vlc_threads.h
>> @@ -750,6 +750,16 @@ void vlc_atomic_notify_all(void *addr);
>>   VLC_API int vlc_clone(vlc_thread_t *th, void *(*entry)(void *), void *data,
>> int priority) VLC_USED;
>>
>> +/**
>> + * Set the thread name of the current thread.
>> + *
>> + * \param name the string to use as the thread name
>> + *
>> + * \note On Linux the name can be up to 16 bytes long, including the
>> terminating +
>> * null byte on Linux. If larger the name will be truncated.
> 
> I think it spells nul.

Not in the pctrl doc. I litterally copied the text.
https://man7.org/linux/man-pages/man2/prctl.2.html

>> + */
>> +VLC_API void vlc_thread_set_name(const char *name);
>> +
>>   /**
>>    * Marks a thread as cancelled.
>>    *
>> diff --git a/src/android/thread.c b/src/android/thread.c
>> index 79132be2e46..02dad44d083 100644
>> --- a/src/android/thread.c
>> +++ b/src/android/thread.c
>> @@ -195,6 +195,14 @@ int vlc_set_priority (vlc_thread_t th, int priority)
>>       return VLC_SUCCESS;
>>   }
>>
>> +void vlc_thread_set_name(const char *name)
>> +{
>> +    char buf[16];       // MAX_TASK_COMM_LEN=16 is hard-coded into bionic
>> +    strncpy(buf, name, 15);
>> +    buf[15] = '\0';
>> +    pthread_setname_np(pthread_self(), buf);
>> +}
>> +
> 
> This is not Android-specific and should be in linux/thread.c.

It is. Unlike the Linux variant, bionic doesn't truncate to 16 bytes, it 
will ignore the value. This is the workaround used by the Java layer in 
current Android.


More information about the vlc-devel mailing list