|
UsageThe design is similar to the standard Java threads - that is, the library provide a base class from which users should derive their own class to do the thread task.To make a thread, define a sub-class of the class thread , and overload the member function threadmm::operator()() to do what you need to do in that thread: #ifndef THREADMM_thread # include <threadmm/thread.hh> #endif class my_thread : public threadmm::thread { private: int _data public: my_thread(int data) : _data(data) {} void* operator()() throw() { std::cout << "Hello there! The data is " << _data << std::endl; return (long int)data; } }; operator() does not take any arguments. Instead, you should define data members and initialise these before you start the thread. Your thread class can now be executed by doing constructing an object, and then calling the memer function threadmm::run on it: my_thread my(10); my.run(); If you'd rather have a thread should contain an object of a class, you can use the class threadmm::object_thread to wrap an object of an arbirary class in a thread. The only requirement is that it defines the functional operator @c void* @c operator()() #ifndef THREADMM_object_thread #include <threadmm/objectthread.hh> #endif class my_thread_object { public: void* operator()() { std::cout << "Hi there!" << endl; } }; my_thread_object o; threadmm::object_thread<my_thread_object> t(o); t.run(); Syncronisation is provided via the mutex and condition classes, and possibly the sempahore , barrier , rwlock , and spinlock classes. Please refer to the Examples for more information. Top of pageLast update Tue Nov 9 12:40:50 2004 Christian Holm Created by DoxyGen 1.3.9.1 |