Class member Boost multiThreading recursion
Apr 13, 2012 at 6:43pm UTC
Hi everybody, I have the following situation:
This code compiling and runing Ok:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#include <iostream>
class ScanFolderTree
{
public :
void ScanFolder(int iLevel)
{
std::cout << "iLevel = " << iLevel << std::endl;
if (iLevel > 10) return ;
iLevel++;
ScanFolder(iLevel);
}
};
int main()
{
ScanFolderTree sft;
sft.ScanFolder(0);
return 0;
}
iLevel = 0
iLevel = 1
iLevel = 2
iLevel = 3
iLevel = 4
iLevel = 5
iLevel = 6
iLevel = 7
iLevel = 8
iLevel = 9
iLevel = 10
iLevel = 11
The next version of above simple program compile
with error like this:
scanFsMltThrd.cpp: In member function ‘void ScanFolderTree::ScanFolder(int)’:
scanFsMltThrd.cpp:16:49: error: no matching function for call to ‘boost::thread_group::create_thread(<unresolved overloaded function type>, int&)’
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
#include <iostream>
#include <boost/thread/thread.hpp>
class ScanFolderTree
{
public :
void ScanFolder(int iLevel)
{
std::cout << "iLevel = " << iLevel << std::endl;
if (iLevel > 10) return ;
iLevel++;
//ScanFolder(iLevel);
//thrds.create_thread(&ScanFolderTree::ScanFolder, iLevel);
//thrds.create_thread(ScanFolder, iLevel);
thrds.create_thread(this ->ScanFolder, iLevel);
}
void JoinAll()
{
thrds.join_all();
}
private :
boost::thread_group thrds;
};
int main()
{
ScanFolderTree sft;
sft.ScanFolder(0);
sft.JoinAll();
return 0;
}
Whoever has experience with this, thanks for any insight.
Topic archived. No new replies allowed.