Setting native OS thread name (eg, via prctl)

Arun Chandrasekaran via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Dec 22 08:05:19 PST 2015


I have this trivial code where the main thread clones a child 
thread.

import std.stdio;
import core.thread;
import std.concurrency;

class DerivedThread : Thread
{
     this()
     {
         super(&run);
     }

     void quit()
     {
         _quit = true;
     }
private:
     void setOSThreadName()
     {
         // TODO: Is there a way to set the native OS thread name, 
worst case, via prctl?
     }
     void run()
     {
         setOSThreadName();
         while(!_quit)
         {
             writeln("Hello from ", thisTid);
             Thread.sleep(dur!("seconds")(1));
         }
         writeln("I'll exit now.");
     }

     bool _quit = false;
     string _threadName = "Derived";
}

void main()
{
     auto derived = new DerivedThread();
     derived.start();
     Thread.sleep(dur!("seconds")(4));
     derived.quit();
     derived.join();
}

What do i have to do to set the thread name in setOSThreadName 
(for instance, on Linux, it will reflect in proc filesystem).


More information about the Digitalmars-d-learn mailing list