in reply to Re^2: shared complex scalars between threads
in thread shared complex scalars between threads

I am trying to increase concurrency as much as possible without creating multiple copies of that large Bayesian model.

Unfortunately, I don't think it will. I got to do a little more experimenting this morning and it seems that creating a shared object this way, (using threads::shared::bless()), simply replicates everything it contains for each thread that gets a handle ;( Sorry if I've wasted your time on this, but I thought that they were doing something clever, but it seems that is not the case. I cannot believe anyone thought this was a useful idea.

The next possibility is to create the big object in a single thread and then have your other threads use it client-server fashion, passing messages detailing the request, and waiting for the reply. This could be done through a queue or individual shared scalars (or even sockets), but whichever way, the requests would effectively be serialised. If the requests are fairly long running and you are hoping to run multiple concurrent requests on different cpus, it isn't going to happen.

I do not currently have a solution to offer you. One possibility involves modifying the internals of Algorithm::NaiveBayes to separate the bulk of the data (currently stored as a complex attribute of the object itself), from the rest of the objects internals and then attempt to have multiple instance of the object share a single shared copy of that bulk of data without cloning. I have a few ideas on this, but nothing that ready for prime time.

Once again. Sorry for any time you have wasted through the bum steer. I should have gone with my gut and stuck with my original misgivings about this feature.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."