Changing Name of a thread

Keywan Ghadami via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jan 9 10:09:21 PST 2016


On Saturday, 9 January 2016 at 17:30:47 UTC, tcak wrote:
> I tried your code with a little addition as follows:
>
> [code]
> import core.sys.posix.pthread;
> import std.string;
> import std.stdio;
>
> extern(C) int pthread_setname_np(pthread_t, const char*);
>
> void main(){
>     pthread_setname_np(pthread_self(), 
> toStringz("thread_name"));
>     readln();
> }
> [/code]
>
> Compiled it with "dmd blah.d", and then run "./blah".
>
> Because there is "readln" there, I opened another terminal and
> used "ps H -o 'pid tid cmd comm'".
>
> In the output:
>
>  PID   TID CMD                         COMMAND
> 5089  5089 ./blah                      thread_name
>
> So, it works.

tcak,
thank you very much, it works!

Maybe interesting for others: The reason for the error message i 
had was, that i declared
     extern(C) int pthread_setname_np(pthread_t, const char*);
within the main method.


More information about the Digitalmars-d-learn mailing list