0

In Linux g++, I do create boost thread like following:

boost::thread *td=new boost::thread(function);

After I run this program, I always check CPU utilization using top -Hp <-process Id>

for example :>

top - 13:50:04 up 27 days, 20:51,  4 users,  load average: 6.08, 6.05, 6.05
Tasks:   9 total,   6 running,   3 sleeping,   0 stopped,   0 zombie
Cpu(s): 37.6%us,  0.0%sy,  0.0%ni, 62.3%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  16425800k total,  8452100k used,  7973700k free,   265468k buffers
Swap: 24579440k total,        0k used, 24579440k free,  3677932k cached

PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
27727 flexsys   25   0 96700 6200 2392 R 100.3  0.0 184:23.42 TRADEMUX
27723 flexsys   25   0 96700 6200 2392 R 100.0  0.0 184:23.40 TRADEMUX
27724 flexsys   25   0 96700 6200 2392 R 100.0  0.0 184:23.42 TRADEMUX
27725 flexsys   25   0 96700 6200 2392 R 100.0  0.0 184:23.40 TRADEMUX
27726 flexsys   25   0 96700 6200 2392 R 100.0  0.0 184:23.41 TRADEMUX
27728 flexsys   25   0 96700 6200 2392 R 100.0  0.0 184:23.39 TRADEMUX
27721 flexsys   18   0 96700 6200 2392 S  0.0  0.0   0:00.01 TRADEMUX
27734 flexsys   15   0 96700 6200 2392 S  0.0  0.0   0:00.62 TRADEMUX
27735 flexsys   15   0 96700 6200 2392 S  0.0  0.0   0:00.63 TRADEMUX

all threads are created by default as same name as the original name of the executable binary.

But I want to create these threads using a specific name dynamically.

How to set name to a boost thread, so that each thread could be named different.
Ankur
  • 330
  • 2
  • 8
  • 17
  • You have to use platform specific functions to set the name, more specifically the non-portable [`pthread_setname_np`](http://man7.org/linux/man-pages/man3/pthread_setname_np.3.html) function (assuming you're on e.g. Linux). – Some programmer dude Dec 12 '14 at 08:33
  • I am using boost 1.55.0 – Ankur Dec 12 '14 at 08:36

0 Answers0