- Fix legit threading issue which shows itself on clang / macos mostly

- Fix all warnings that I can / ignore those caused by boost
This commit is contained in:
Jason Turner
2013-05-26 22:47:23 -06:00
parent feb344e744
commit 101225aa68
10 changed files with 109 additions and 21 deletions

View File

@@ -25,13 +25,17 @@ int expected_value(int num_iters)
void do_work(chaiscript::ChaiScript &c, int id)
{
std::stringstream ss;
ss << "MyVar" << rand();
c.add(chaiscript::var(5), ss.str());
ss.str("");
ss << id;
c.use("multithreaded_work.inc");
c("do_chai_work(4000, " + ss.str() + ");");
try{
std::stringstream ss;
ss << "MyVar" << rand();
c.add(chaiscript::var(5), ss.str());
ss.str("");
ss << id;
c.use("multithreaded_work.inc");
c("do_chai_work(4000, " + ss.str() + ");");
} catch (const std::exception &e) {
std::cout << "exception: " << e.what() << " thread: " << id;
}
}
int main()
@@ -65,20 +69,17 @@ int main()
chaiscript::ChaiScript chai(modulepaths,usepaths);
std::vector<boost::shared_ptr<boost::thread> > threads;
boost::thread_group threads;
// Ensure at least two, but say only 7 on an 8 core processor
int num_threads = std::max<unsigned int>(boost::thread::hardware_concurrency() - 1, 2u);
for (int i = 0; i < num_threads; ++i)
{
threads.push_back(boost::shared_ptr<boost::thread>(new boost::thread(boost::bind(do_work, boost::ref(chai), i))));
threads.create_thread(boost::bind(&do_work, boost::ref(chai), i));
}
for (int i = 0; i < num_threads; ++i)
{
threads[i]->join();
}
threads.join_all();
for (int i = 0; i < num_threads; ++i)