Hello, I create a thread group and run the group with join_all(). My code shows like: for(i=0; i < runs; ++i) { threadgoup.join_all(); do something with the results } So I run the thread group n times. Is this the correct way or can I call join_all only once on the group? Thanks PHil
I create a thread group and run the group with join_all(). My code shows like: for(i=0; i < runs; ++i) { threadgoup.join_all(); do something with the results } So I run the thread group n times. Is this the correct way or can I call join_all only once on the group?
You do not "run the group with join_all". join_all() waits (blocks) until the execution of all the threads in the group is complete - that's all. This is well documented: http://www.boost.org/doc/libs/1_47_0/doc/html/thread/thread_management.html#...
Am 11.09.2011 um 22:14 schrieb Igor R:
I create a thread group and run the group with join_all(). My code shows like: for(i=0; i < runs; ++i) { threadgoup.join_all(); do something with the results } So I run the thread group n times. Is this the correct way or can I call join_all only once on the group?
You do not "run the group with join_all". join_all() waits (blocks) until the execution of all the threads in the group is complete - that's all.
That's correct, because the calls after the join_all need the results of all threads. The algorithm, that I use, has some parallel and serial parts, so I would run the parallel party with a thread group, wait until the group has finished and run the serial part.
This is well documented: http://www.boost.org/doc/libs/1_47_0/doc/html/thread/thread_management.html#...
I have read the documentation, but there is only the postcondition explained "Every thread in the group has terminated". The algorithm is a iteration algorithm, so I have create code like this: creating thread group for(i=0; i < iterations; ++i) { run threadgroup for parallel part, till all threads finished run serial part } So I would like to ask for, if the thread group is created, and I call the join_all within the loop, each "join_all" starts the full group again on each iteration or need I create a new threadgroup on each iteration (join_all can be called only once on a group)? Thanks Phil
creating thread group for(i=0; i < iterations; ++i) { run threadgroup for parallel part, till all threads finished run serial part }
So I would like to ask for, if the thread group is created, and I call the join_all within the loop, each "join_all" starts the full group again on each iteration or need I create a new threadgroup on each iteration (join_all can be called only once on a group)?
join_all() waits (blocks) until the execution of all the threads in the group is complete - *that's all*. In other words: join_all(), like thread::join(), does not start anything. It just waits until thread completes. So at the end of every iteration you don't have threads anymore -- if you need them again, you have to create another ones.
Am 11.09.2011 um 22:46 schrieb Igor R:
creating thread group for(i=0; i < iterations; ++i) { run threadgroup for parallel part, till all threads finished run serial part }
So I would like to ask for, if the thread group is created, and I call the join_all within the loop, each "join_all" starts the full group again on each iteration or need I create a new threadgroup on each iteration (join_all can be called only once on a group)?
join_all() waits (blocks) until the execution of all the threads in the group is complete - *that's all*. In other words: join_all(), like thread::join(), does not start anything. It just waits until thread completes. So at the end of every iteration you don't have threads anymore -- if you need them again, you have to create another ones.
Thanks, I understand, so my group is after join_all empty, so I change my code to: for(i=0; i < iteration; ++i) { create thread group run thread group with join_all for parallel part run serial part } so on each iteration I need to create a new thread group Thanks Phil
Thanks, I understand, so my group is after join_all empty, so I change my code to:
for(i=0; i < iteration; ++i) { create thread group run thread group with join_all for parallel part run serial part }
so on each iteration I need to create a new thread group
The group is not empty, it contains all those boost::thread objects you put there. But actual threads associated with those objects are already over at this point. So you have to create & launch another ones.
Am 12.09.2011 um 08:14 schrieb Igor R:
Thanks, I understand, so my group is after join_all empty, so I change my code to:
for(i=0; i < iteration; ++i) { create thread group run thread group with join_all for parallel part run serial part }
so on each iteration I need to create a new thread group
The group is not empty, it contains all those boost::thread objects you put there. But actual threads associated with those objects are already over at this point. So you have to create & launch another ones.
That's my question, I have create a thread groups with object and run them. I would like to run the same objects with the same parameters again, so need I (re)create the objects within the group again or can I use the group with a new join_all again (without recreating)? I would like to use my thread objects again with the waiting option join_all. Thanks Phil
That's my question, I have create a thread groups with object and run them. I would like to run the same objects with the same parameters again, so need I (re)create the objects within the group again
Yes, you have to recreate them. Quoting from the documentation: "A new thread is launched by passing an object of a callable type that can be invoked with no parameters to the constructor. The object is then copied into internal storage, and invoked on the newly-created thread of execution." http://www.boost.org/doc/libs/1_47_0/doc/html/thread/thread_management.html
Looks like you need something like a barrier:
http://www.boost.org/doc/libs/1_47_0/doc/html/thread/synchronization.html#th...
2011/9/11 Kraus Philipp
Am 11.09.2011 um 22:14 schrieb Igor R:
I create a thread group and run the group with join_all(). My code shows like: for(i=0; i < runs; ++i) { threadgoup.join_all(); do something with the results } So I run the thread group n times. Is this the correct way or can I call join_all only once on the group?
You do not "run the group with join_all". join_all() waits (blocks) until the execution of all the threads in the group is complete - that's all.
That's correct, because the calls after the join_all need the results of all threads. The algorithm, that I use, has some parallel and serial parts, so I would run the parallel party with a thread group, wait until the group has finished and run the serial part.
This is well documented: http://www.boost.org/doc/libs/1_47_0/doc/html/thread/thread_management.html#...
I have read the documentation, but there is only the postcondition explained "Every thread in the group has terminated". The algorithm is a iteration algorithm, so I have create code like this:
creating thread group for(i=0; i < iterations; ++i) { run threadgroup for parallel part, till all threads finished run serial part }
So I would like to ask for, if the thread group is created, and I call the join_all within the loop, each "join_all" starts the full group again on each iteration or need I create a new threadgroup on each iteration (join_all can be called only once on a group)?
Thanks
Phil
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (3)
-
Igor R
-
Kraus Philipp
-
Ytsen de Boer