3 ms·
The thread pool normally just allows you to execute code (think void() lambdas). Returning values to the caller isn’t something they normally do, but is normall
by jupp0r 7y ago
The thread pool normally just allows you to execute code (think void() lambdas). Returning values to the caller isn’t something they normally do, but is normally managed by higher level concurrency libraries like facebooks folly or libq (among others).
- MaxBarraclough 7y agoAh yes of course, auto result = pool.enqueue.... is blocking. Oh dear.
- jupp0r 7y agoThe assigment isn’t, but result.get() is (potentially, if computation hasn’t finished yet).
- MaxBarraclough 7y agoAh yes, I skimmed the code too quickly. Again :-P The result local holds a future/task, not the result itself, and get() may force a synchronous wait, like Task#Result in .Net. Somewhat related ramblings: I couldn't have misread the code in this way were it not for C++'s new type-inference with auto. In C#, I generally only use type-inference when first writing a statement, and then have the IDE substitute the var keyword to give a traditional 'explicit' declaration. Explicit types greatly help a codebase to be 'self-documenting'. Readability outweighs writing speed.