<code>for (int i = 0; i < 100; i++)
threadPool.post([=]() {
auto result = // do some complex tasks;
ofstream os("test-" + i);
os << result;
});
</code>
<code>for (int i = 0; i < 100; i++)
threadPool.post([=]() {
auto result = // do some complex tasks;
ofstream os("test-" + i);
os << result;
});
</code>
for (int i = 0; i < 100; i++)
threadPool.post([=]() {
auto result = // do some complex tasks;
ofstream os("test-" + i);
os << result;
});
Lets say thread pool has a thread num of 10, and I want to write 100 files.
Is writing in parallel better than storing the result and write afterwards? Or the opposite?
Will ofstream block other threads when destructing (because of trying to write file to the same device)?
And does reading multiple files in parallal speed up reading?
New contributor
Richard Luo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.