www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Setting native OS thread name (eg, via prctl)

reply Arun Chandrasekaran <aruncpp0 gmail.com> writes:
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).
Dec 22 2015
parent reply Dejan Lekic <dejan.lekic gmail.com> writes:
Arun, isn't that what the 'name' property is there for?
Dec 22 2015
parent Arun Chandrasekaran <aruncpp0 gmail.com> writes:
On Tuesday, 22 December 2015 at 16:08:01 UTC, Dejan Lekic wrote:
 Arun, isn't that what the 'name' property is there for?
Hi Dejan, Thanks for a quick reply. Setting the name property is not reflecting in the OS level. May be it is just used only at the object level? After setting the thread name, I would like to see the it reflect, for instance, in the output of `top` command. You can press H in top to toggle threads and see their names there. Cheers.
Dec 22 2015