I currently have a code block like this
UINT8* u = getResult();
for (UINT64 counter = 0; counter < MaxCount; counter++)
{
for (UINT64 index = 0; index < c_uOneMB; ++index)
{
*u++ = genValue();
}
}
Now in order to make this run faster. I am doing something like this. Basically splitting the inner thread into a method. However I have two concerns which I am not sure how to tackle.
- *u++ how do I handle that?
- Before calling doSomethingElse() all the threads need to .join()
Any suggestions on how to accomplish that?
void doSomething(UINT8* u)
{
for (UINT64 index = 0; index < c_uOneMB; ++index)
{
*u++ = genValue();
}
}
UINT8* u = getResult();
for (UINT64 counter = 0; counter < MaxCount; counter++)
{
std::thread t(doSomething,u);
}
doSomethingElse();
>Solution :
With little details you have provided I can give only this:
std::generate_n(std::execution::par, getResult(), MaxCount * c_uOneMB, genValue);
- https://en.cppreference.com/w/cpp/algorithm/generate_n
- https://en.cppreference.com/w/cpp/algorithm/execution_policy_tag