C library to get the number of active threads

I am developing a multi-threaded Unix application in C. Is there an easy way to get the number of concurrently active threads? I do not want to write code to track the number of active threads, if this can already be done for me by the library !:-)

I am using POSIX pthreads and I am trying to write as portable as possible code for Unix and Unix-like systems.

+3
source share
2 answers

No, not in pthreads per se. POSIX Threads tries to specify only primitives or basic utility constructs, and considers even pthread_joina convenience function, not a primitive .

Some libraries may offer intolerable solutions (for example, look at _npthe name on HP-UX), but for pthreads as such, you are on your own.

+6
source

I could take into account its quantity in the constructor / destructor, but make sure that you deal with it at the same time to avoid race conditions.

+1
source

Source: https://habr.com/ru/post/1722542/


All Articles