Boost logo

Boost Users :

Subject: [Boost-users] Beginning with thread
From: Kraus Philipp (philipp.kraus_at_[hidden])
Date: 2010-08-13 07:46:35


Hi,

I would like to use Boost threads, but I don't work with them. I know
only Java Threads.

The problem, in which should use threads:
I have some stochastic and numerical optimization, which all can
calculate independent (no mutex, synchronizsation or something else).

I've found boost::thread and boost::bind for creating threads (call a
method of an object).

In Java I would write this code structure:

myThread first = new myThread();
first.setParameter1(....)
first.setParameter1(....)

Thread th = new Thread(first);
th.start();

first.getData()

I would like to have an object of calculation, which receives only
after creating different parameters and then calculates the data on
more than one thread.
After completion of the calculation, I can let me deliver the data
back from any object, like:

std::vector<myWorker> x;
for(int i=0; i < numThreads; ++i) {
      x.push_back( myWorker() );
      x[i].setParameter(....);
}

createThreadGroup (x);
wait until ThreadGroup is finish

for(int i=0; i < numThreads; ++i)
     x[i].getData()

How can do this with Boost Thread? Is this the correct way or can I do
this more efficient?

Thanks

Phil


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net