3

I'm developing a multi threaded Unix application in C. Is there a simple way to get the count of the number of simultaneously active threads? I don't want to have to write the code to keep track of the number of active thread if it already can be done for me by the library! :-)

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

2
  • Depends on your threading library. What threading library are you using, and on what platform? Clarify the question, please. Commented Nov 11, 2009 at 5:12
  • clarification has been added! Commented Nov 11, 2009 at 5:20

2 Answers 2

6

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

Certain libraries may offer non-portable solutions (look for _np in the name on HP-UX, for instance), but for pthreads per se, you're on your own.

Sign up to request clarification or add additional context in comments.

2 Comments

@anonymous_downvoters, please detail your reasons for the downvotes!
Yeah, that was weird. I upvoted this one when I saw the downvotes. Please, give details on why.
1

You could I guess keep a count of it in the constructor/destructor but make sure you handle it concurrently as to avoid race conditions.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.