# std.Thread.setName: use unused code · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/0b2ee093788ba84c5d130c021f347844b5939889)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 0b2ee093788ba84c5d130c021f347844b5939889

Requested commit: 0b2ee093788ba84c5d130c021f347844b5939889

Commit: 0b2ee093788ba84c5d130c021f347844b5939889

Tree: a03166a9379bbad387a7177e649419ed43dbece0

Author: r00ster91

Committer: r00ster91

## Message

```
std.Thread.setName: use unused code

I noticed a comment saying that the intent of a code's author was unclear.
What happened is that the author forgot to put the check for whether the
thread is the calling thread (`self.getHandle() ==
std.c.pthread_self()`) in the `if (use_pthreads)`.
If the thread is the calling thread, we use `prctl` to set or get the
thread's name and it does not take a thread id because it knows the id
of the thread we're calling `getName` or `setName` from.
I have found a source saying that using `pthread_setname_np` on either the calling thread
or any other thread by thread id would work too (so we don't need to
call `prctl`) but I was not sure if that is the case on all systems
so we keep using `pthread_setname_np` if we have a
specific thread that is not the thread we're calling from, and `prctl`
otherwise.

```

## Parents

- [c9e02d3e69f909a6eb215286c6109f2b3f1e68a2](https://git.cafe/gitcafe/zig/commit/c9e02d3e69f909a6eb215286c6109f2b3f1e68a2?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/0b2ee093788ba84c5d130c021f347844b5939889?format=markdown)
