#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
+#include <list>
#include <iostream>
boost::mutex io_mutex; // The iostreams are not guaranteed to be thread-safe!
int count;
};
+
counter c;
void change_count()
}
+class worker {
+public:
+ void operator() (void) {
+ int i = c.increment();
+
+ i = c.increment();
+
+ i = c.increment();
+ boost::mutex::scoped_lock scoped_lock(io_mutex);
+ std::cout << "count == " << i << std::endl;
+ }
+ virtual ~worker() { std::cout << "destroyed\n"; }
+};
+
+
int main(int, char*[])
{
{
const int num_threads = 4;
boost::thread_group thrds;
+
+ std::list<boost::thread *> thread_list;
+
for (int i=0; i < num_threads; ++i)
- thrds.create_thread(&change_count);
+ {
+ // thrds.create_thread(&change_count);
+ worker *w = new worker;
+
+ boost::thread *thr = new boost::thread(*w);
+
+ thrds.add_thread(thr);
+
+ thread_list.push_back(thr);
+ }
thrds.join_all();
-
+#if 0
+ std::list<boost::thread *>::iterator it;
+ for (it = thread_list.begin(); it != thread_list.end(); it++)
+ {
+ delete *it;
+ *it = 0;
+ }
+#endif
}
catch (std::exception &e)
{
//#include "router.hpp"
//#include "package.hpp"
- #define BOOST_AUTO_TEST_MAIN
- #include <boost/test/auto_unit_test.hpp>
+#define BOOST_AUTO_TEST_MAIN
+#include <boost/test/auto_unit_test.hpp>
//#include <boost/test/unit_test.hpp>
//#include <boost/test/unit_test_monitor.hpp>
BOOST_AUTO_TEST_CASE( test1 )
{
-
try{
- TFilter filter;
-
- filter.name("filter1");
-
- BOOST_CHECK (filter.name() == "filter1");
-
- filter.name() = "filter1 rename";
-
- BOOST_CHECK(filter.name() == "filter1 rename");
+ TFilter filter;
+
+ filter.name("filter1");
+
+ BOOST_CHECK (filter.name() == "filter1");
+
+ filter.name() = "filter1 rename";
+
+ BOOST_CHECK(filter.name() == "filter1 rename");
}
-
catch(std::runtime_error &e ){
BOOST_CHECK (true);
}
catch ( ...) {
BOOST_CHECK (false);
}
-
-
}
/*