-----------------------------------------------------------------------------------------------
boost::thread_specific_ptr <ifstream> infile;
boost::thread_specific_ptr< std::vector<std::string> > file_buffer;
boost::thread_specific_ptr<std::string> TempLine;
//more ptrs here
void ReadFile(wxString FileName)
{
infile.reset(new ifstream);
file_buffer.reset ( new std::vector<std::string> );
TempLine.reset ( new std::string );
//init other ptrs here
//open file, etc here (@infile)
//read contents into vector line by line
while ( ! infile.get()->eof() )
{
getline(*infile,*TempLine);
file_buffer.get()->push_back(*TempLine);
}
//other operations on file_buffer below ...........
}
void CallFunc()
{
boost::filesystem::path p(TEMP_PATH); //refers to class member
boost::filesystem::directory_iterator itr(p);
boost::filesystem::directory_entry & entry = *itr;
boost::filesystem::directory_iterator end_itr;
std::vector< boost::thread* > t;
int total_files = std::count_if( directory_iterator(p), directory_iterator(), bind( static_cast<bool(*)(const path&)>(is_regular_file), bind( &directory_entry::path, _1 ) ) );
for (; itr!=end_itr; ++itr)
{
//read files, create threads
t.push_back( new boost::thread(&ReadFile, this, entry.path().filename().string() ) ) ;
t->join(); //app freezes here, if i detach() instead of join it's fine
//some other stuff
}
//delete thread pointers, etc ( join() before delete )
}
------------------------------------------------------------------------------------------------
Hope that helps