On 4/02/11 8:23 PM, Jesse Phillips wrote:
Peter Alexander Wrote:

Essentially, the work that doWork does needs to be returned to the main
thread asynchronously, and obviously in a thread-safe manner.

What's the best way to do this? The above won't work because ~= isn't
atomic, so you can't do it on shared data.

Disclaimer: I don't really do much with threading/concurrency.

You might look at using parallelfuture, the library to be added to Phobos as 
parallelism. An example similar to yours, though instead of the doWork getting 
a thread it is the doStuff function, and this example is for a call center:

https://gist.github.com/774983

Call =>  LoadsOfData
callGenerator =>  doWork
Threed.sleep =>  doStuff

You will probably also want to return an Immutable Call from callGenerator, 
that should result in a non-copy share (Though maybe it already does that).

You may also want to look at std.concurrency and make use of message passing.

https://gist.github.com/773979

Hopefully this are a good starting place.

Thanks, I'll take a look at parallelism.

How would you do it with message passing though? As I understand, all of the std.concurrency message passing routines are blocking, and I need this to be asynchronous.

Reply via email to