请问大家一个循环如何用TBB优化。

hapton1234 2009-04-11 06:38:12
while(true)
{
//do something
}
如何用ttb优化,使得多核cpu的任务分配均匀,难道说用把scheduler初始化,然后把代码放到初始化与终了之间,系统自动完成分配???
...全文
225 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
intel_zhenyuwang 2009-04-13
  • 打赏
  • 举报
回复
使用类 tbb_thread -
namespace tbb {
class tbb_thread {
public:
class id;
tbb_thread();
template <class F> explicit tbb_thread(F f);
template <class F, class X> tbb_thread(F f, X x);
template <class F, class X, class Y> tbb_thread (F f, X x, Y y);
~tbb_thread();
bool joinable() const;
void join();
void detach();
id get_id() const;
native_handle_type native_handle();
static unsigned hardware_concurrency();
};
} // namespace tbb

调用例子:查询顾客-
typedef std::pair< tbb::tbb_thread::id, int > pos_t;
tbb::concurrent_queue< pos_t > positions;

finished = false;

tbb::tbb_thread t (
[&] () { while (!finished || positions.size() > 0) {
pos_t p;
if ( positions.pop_if_present(p) )
std::cout << "Thread " << p.first
<< "found value "
<< value_to_find << " at position "
<< p.second << std::endl;
else
tbb::this_tbb_thread::yield();

}
}
);

567

社区成员

发帖
与我相关
我的任务
社区描述
英特尔® 边缘计算,聚焦于边缘计算、AI、IoT等领域,为开发者提供丰富的开发资源、创新技术、解决方案与行业活动。
社区管理员
  • 英特尔技术社区
  • shere_lin
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧