Hi,
I create some boost::threads:
std::vector< worker<T,D> > l_worker;
boost::thread_group l_threadgroup;
for(std::size_t i=0; i < p_threads; ++i) {
l_worker.push_back( worker<T,D>(p_iteration, p_stepsize, m_fulltable, m_derivation, m_optimize, m_static, p_batch) );
l_threadgroup.create_thread( boost::bind( &worker<T,D>::optimize, l_worker[i] ) );
}
l_threadgroup.join_all();
In the constructor of my worker-object makes a copy of the parameters ( p_iteration = std::size_t, p_stepsize = T (double), p_batch = std::vector and the others are std::map):
... ) :
m_iteration( p_iteration ), m_stepsize( p_stepsize ), m_symbols(), m_derivation(), m_initvalues(), m_staticvalues(),
m_batch()
{
std::copy( p_derivation.begin(), p_derivation.end(), std::inserter(m_derivation, m_derivation.begin()));
std::copy( p_initvalues.begin(), p_initvalues.end(), std::inserter(m_initvalues, m_initvalues.begin()));
std::copy( p_syms.begin(), p_syms.end(), std::inserter(m_symbols, m_symbols.begin()));
}
in the optimize-method I use this code:
GiNaC::exmap l_dynamic; // exmap is == std::map
for(typename std::map<std::string, std::pair<T,T> >::iterator it = m_initvalues.begin(); it != m_initvalues.end(); ++it)
l_dynamic[ m_symbols[it->first] ] = it->second.first;
If I create only one thread, everything works fine. On more thread I'll get
main(4398,0xa07ad720) malloc: *** error for object 0xd2b880: incorrect checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug
My idea is to create p_threads number of my worker objects and add some data with the constructor parameters. Than I call the join_all method so every object can work with their own data and after join_all is finished I receive the data from every object.
Can someone please explain to me what I did wrong.
Thanks
Phil