openMP

David Nadlinger see at klickverbot.at
Wed Oct 3 13:56:19 PDT 2012


On Wednesday, 3 October 2012 at 19:42:07 UTC, dsimcha wrote:
> If not, please clarify what you needed and the relevant use 
> cases so that I can fix std.parallelism.

In my use case, conflating the notion of a future, i.e. a value 
that becomes available at some point in the future, with the 
process which creates that future makes no sense.

For example, let's say you are writing a function which computes 
a complex database query from its parameters and then submits it 
to your query manager/connection pool/… for asynchronous 
execution. You cannot use std.parallelism.Task in this case, 
because there is no way of expressing the process which retrieves 
the result as a delegate running inside a TaskPool.

Or, say you want to write an "aggregator", combining the results 
of several futures together, again offering the same future 
interface (maybe an array of the original result types) to 
consumers. Again, there is no computation-bound part to that at 
all, which would make sense to run on a TaskPool – you are only 
waiting on the other tasks to finish.

The second problem with std.parallelism.Task is that your only 
choice is polling (or blocking, for that matter). Yes, callbacks 
are a hairy thing to do if you can't be sure what thread they are 
executed on, but not having them severely limits the power of 
your abstraction, especially if you are dealing with 
non-CPU-bound tasks (as many of today's "modern" use cases are).

For example, something my mentor asked to implement for Thrift 
during last year's GSoC was a feature which allows to send a 
request out to a pool of servers concurrently, returning the 
first one of the results (apparently, this mechanism is used as a 
sharding mechanism in some situations – if a server doesn't 
have the data, it simply ignores the request). How would you 
implement something like that as a function Task[] -> Task? For 
what it's worth, Task in C# (which is quite universally praised 
for its take on the matter) also has a »ContinueWith« method 
which is really just a completion callback mechanism.

std.parallelism.Task is great for expressing local 
resource-intensive units of work (and fast!), but I think it is 
to rigid and specialized for that case to be generally useful.

David


More information about the Digitalmars-d mailing list