- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Another quick question.
What is the best way to get the max number of physical threads, thread::hardware_concurrency or task_scheduler_init::default_num_threads? Do these static methods return the same number?
Just curios, why the first one returns unsigned, but the second one returns int?
Thanks in advance,
renorm.
What is the best way to get the max number of physical threads, thread::hardware_concurrency or task_scheduler_init::default_num_threads? Do these static methods return the same number?
Just curios, why the first one returns unsigned, but the second one returns int?
Thanks in advance,
renorm.
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting renorm
What is the best way to get the max number of physical threads, thread::hardware_concurrency or task_scheduler_init::default_num_threads? Do these static methods return the same number?
Just curios, why the first one returns unsigned, but the second one returns int?
Just curios, why the first one returns unsigned, but the second one returns int?
The latetr one was part of the initial TBB release that did not have any thread abstraction class. It returns int to make it compatible with argument types of other methods, which sometimes use special values (like -1 or -2). I guess it were possible to make them all unsigned, but doing so would've reqiured too many explicit casts between signed/unsigned in the code that uses deltas to increment/decrement the number of active threads. And thus it was decided to leave it int.
When later we introduced class tbb::tbb_thread that has become std::thread (though still available via tbb:: namespace) by now, we made it as close to the C++0x draft as possible. And the draft in particular requires method std::thread::hardware_concurrency to return unsigned.
Thus we maintain both methods for compatibility reasons, and they return the same value.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page