diff options
author | 2024-06-05 16:06:33 -0700 | |
---|---|---|
committer | 2024-06-26 19:40:34 +0000 | |
commit | 330fb44dd9845a229ac1024fab0eed366ac2ab69 (patch) | |
tree | 7e1ed7777d362e4234561f0fa73a22570f832a5e /libartbase/base/utils.h | |
parent | 83cc7f2316fe6f3584483543b54033bd7885b0db (diff) |
Add 2275-pthread-name test for Thread.setName
This checks that we set the pthread name correctly in response to
Thread.setName() calls.
We did not. In fact, we incorrectly set the pthread name for the calling
thread, rather than the `this` thread.
Fix that, by never erroneously setting the calling threads name, and by
making a good effort to set the correct one. This difers from the
documented RI behavior of setting the pthread name only if this == self.
That decision is not a slam dunk either way, and opinions are welcome.
This approach almost certainly matches naive expectations more of the
time, but it currently has the disadvantage that it can fail under much
less common, but also much less predictable, circumstances.
It could possibly be made fully predictable if we managed to clean
up some other issues, which I highlighted in the code.
Test: Host run tests, Treehugger
Change-Id: I295e0af0157a530919df4120c5dbf347dd9416a2
Diffstat (limited to 'libartbase/base/utils.h')
-rw-r--r-- | libartbase/base/utils.h | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/libartbase/base/utils.h b/libartbase/base/utils.h index b5e03dcdb8..32f8b87204 100644 --- a/libartbase/base/utils.h +++ b/libartbase/base/utils.h @@ -65,10 +65,14 @@ uint32_t GetTid(); // Returns the given thread's name. std::string GetThreadName(pid_t tid); -// Sets the name of the current thread. The name may be truncated to an +// Sets the pthread name of the current thread. The name may be truncated to an // implementation-defined limit. void SetThreadName(const char* thread_name); +// Sets the pthread name of the given thread. The name may be truncated to an +// implementation-defined limit. Does nothing if not supported by the OS. +void SetThreadName(pthread_t thr, const char* thread_name); + // Reads data from "/proc/self/task/${tid}/stat". void GetTaskStats(pid_t tid, char* state, int* utime, int* stime, int* task_cpu); |