开发者

boost thread_group with callback

i would like to write a boost::thread_group. Assuming i understood correctly what callback in thread is i would like to apply it as well in my program.

I found the following example: (thread_group with out callback)

 boost::thread_group group;
 for (int i = 0; i < 15; ++i)
      group.create_thread(aFunctionToExecute);
 group.join_all();

If i would like to change it to callback, will it simply be adding & before aFunctionToExecute?

I thought about using callback for the following case: Assuming i have 2 cores and my for-loop is from 0 to 99 (100 elements). Instead of open 100 threads , i would like to open only 2 thread (the number of cores in this example) and after each thread finish its computation with the correct variable, that it will send something that it is done and wait for order to run again until all 100 elements will be computed.

Does someone know an example or few example that i could combin开发者_JAVA百科e creating this?

since i have not really experience in threading, i would like to know is this way of applying group_threads is the "right" way?

Reagrds

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜