/ Published in: C++
Expand |
Embed | Plain Text
// Joshua Calloway // cspp51045 // 17-1 // #include <iostream> #include <boost/thread/thread.hpp> #include <boost/thread/mutex.hpp> using namespace std; boost::mutex io_mutex; struct counter { counter(int id) : id(id) {} void operator()() { for (int i = 0; i < 100; i++) { boost::thread::yield(); boost::mutex::scoped_lock lock(io_mutex); cout << "Thread " << id << " been called " << i << " times." << endl; } } int id; }; int main() { boost::thread_group thrds; thrds.add_thread(new boost::thread(counter(1))); thrds.add_thread(new boost::thread(counter(2))); thrds.add_thread(new boost::thread(counter(3))); thrds.join_all(); return 0; }
You need to login to post a comment.
