Thank you for your quick reply. I am now starting to see how it should be used.
As a little bit of encouragement, your code is being used in in-house
applications doing millions to trillions of calculations that are creating
leading edge economic data.
Thank you again,
Jonathan
dsimcha wrote:
== Quote from Jonathan Crapuchettes ([email protected])'s article
I've been looking at your std.parallelism module and am really interested in it,
but there is one problem that I have run into that I can't seem to find a
solution. If I have code that requires a database connection in each thread, I
don't really want to be creating and then deleting a lot (e.g. 500,000) of
connections while using taskPool.parallel. Normally I would create a set of
objects that extend Thread and create a single connection in each. Can you offer
a suggestion how I might handle this situation?
These kinds of situations are **exactly** what worker-local storage is for.
Roughly:
// new MysqlConnection() is lazy, you get one per worker thread.
auto connections = taskPool.workerLocalStorage(new MysqlConnection());
foreach(element; taskPool.parallel(array)) {
// Get the worker-local instance of connection.
auto connection = connections.get;
// Do stuff.
}
// Now that we're done with the parallel part of the algorithm,
// we can access all the connections to free them.
foreach(c; connections.toRange) {
c.free();
}