
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Wednesday 14 May 2008 16:24 pm, James Sutherland wrote:
Phil, Thank you for your suggestions - I am hunting in the dark here...
for( int itask=0; itask<nTasks; ++itask ){ boost::thread_group threads; for( int i=0; i<nThreads; ++i ){ threads.create_thread( MyStruct(itask++ + 100) ); } threads.join_all(); }
Did you really want the ++itask in the first for() ? Isn't it being incremented enough in the create_thread line?
This was intentional. This highly contrived example creates a fixed amount of work (nTasks) and divides them up among nThreads threads. As a thread takes a task, I increment itask. Strange, I know...
No, if you also increment itask in the outer loop, you are doing fewer tasks when nThreads is smaller. Although, what I said before about creating more threads than you think was wrong (I misunderstood your program). - -- Frank -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFIK0065vihyNWuA4URArbpAJ9OS3wPEJ1/FQfDyrt4TEbJ60QWyACeM4zZ X870SRnIAMmWejzw/iTtxYs= =Je0u -----END PGP SIGNATURE-----