I am going over c++ concurrency and have question for those well versed in this area. I used simple binary which launches thread and display its status. THere is no IPC communication just CONFIG_NUM_THREAD number of threads running with same function.
In the function, I used std::thread::get_id() to get thread ID but it displays huge numbers. I used linux ps axms to display the status which displays PID/PPID/LWP (lightweight process) column however they dont match?
Do we expect that the threads ID-s returned by std::thread::get_id() expected to return same thread ID displayed under LWP column of ps axms command?
Here is my program output and get_id() values are enclosed in parameters, all starting with 7f...
1 2 3 4 5 6 7 8 9 10
(7f2065be5700)4: Hello CONCURRENT WORLD, sleeping for 21
(7f20651e4700)5: Hello CONCURRENT WORLD, sleeping for 24
(7f20665e6700)3: Hello CONCURRENT WORLD, sleeping for 2f
(7f20647e3700)6: Hello CONCURRENT WORLD, sleeping for 2d
(7f2063de2700)7: Hello CONCURRENT WORLD, sleeping for 2b
(7f2066fe7700)2: Hello CONCURRENT WORLD, sleeping for 2d
(7f20633e1700)8: Hello CONCURRENT WORLD, sleeping for 24
(7f20629e0700)9: Hello CONCURRENT WORLD, sleeping for 20
(7f20679e8700)1: Hello CONCURRENT WORLD, sleeping for 1d
(7f20683e9700)0: Hello CONCURRENT WORLD, sleeping for 15
C++ threads on linux are implemented using the pthread API so std::this_thread::get_id() returns the same value as pthread_self(). I quickly checked the glibc implementation and it seems like the thread id is just a pointer to the thread's stack that has been casted into an integer type.