I'm trying to find a better way to essentially stream the for loop. For example, if I have the following loop:
for(int i = 0; i < n; i++)
doSomethingThreadSafe(i);
It will be on a Windows platform. I played with creating a thread for each processor, and then trying to split n as evenly as possible for each processor. Then I pass the necessary data to each thread, and then use WaitForMultipleThreads. Is there a better way to do this? I do not want to use any other library, for example boost.
Ideally, I would like some kind of general (possibly boilerplate) way around this. i.e.
threaded_for(0, n, doSomethingThreadSafe);
If the best / most efficient way is to use the library, how much work will be required to add the library and how exactly it will be used in this example. However, I prefer the solution without having to add another.
source
share