Handle std::thread::hardware_concurrency()

前端 未结 2 659
轻奢々
轻奢々 2021-02-11 00:25

In my question about std::thread, I was advised to use std::thread::hardware_concurrency(). I read somewhere (which I can not find it and seems like a

2条回答
  •  孤独总比滥情好
    2021-02-11 01:17

    Based on common predefined macros link, kindly provided by Joachim, I did:

    int p;
    #if __GNUC__ >= 5 || __GNUC_MINOR__ >= 8 // 4.8 for example
      const int P = std::thread::hardware_concurrency();
      p = (trees_no < P) ? trees_no : P;
      std::cout << P << " concurrent threads are supported.\n";
    #else
      const int P = my_hardware_concurrency();
      p = (trees_no < P) ? trees_no : P;
      std::cout << P << " concurrent threads are supported.\n";
    #endif
    

提交回复
热议问题