Asynchronous concurrency with reference types

Jesse Phillips jessekphillips+D at gmail.com
Fri Feb 4 12:23:46 PST 2011


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.


More information about the Digitalmars-d-learn mailing list