2 #include <boost/thread/mutex.hpp>
3 #include <boost/thread/thread.hpp>
6 boost::mutex io_mutex; // The iostreams are not guaranteed to be thread-safe!
11 counter() : count(0) { }
14 boost::mutex::scoped_lock scoped_lock(mutex);
27 int i = c.increment();
28 boost::mutex::scoped_lock scoped_lock(io_mutex);
29 std::cout << "count == " << i << std::endl;
34 int main(int, char*[])
38 const int num_threads = 4;
39 boost::thread_group thrds;
40 for (int i=0; i < num_threads; ++i)
41 thrds.create_thread(&change_count);
46 catch (std::exception &e)
48 std::cout << e.what() << "\n";
57 * indent-tabs-mode: nil
59 * vim: shiftwidth=4 tabstop=8 expandtab