///////////////////////////////////////////////////////////////////// // threads.cpp - generic class supporting creation of threads // // ver 1.0 // // Language: Visual C++, ver 6.0, SP 5 // // Platform: Dell Dimension 8100, Win 2000 Pro, SP 2 // // Application: CSE691/791 - SWM&A Demonstration // // Author: Jim Fawcett, CST 2-187, Syracuse Univ // // (315) 443-3948, jfawcett@twcny.rr.com // // // ///////////////////////////////////////////////////////////////////// #ifdef TEST_TMPLTHRDS //----< test stub >-------------------------------------------------- #include "tmplThrds.h" #include using namespace std; #include "lockingPtr.h" using namespace std; class proc1 { public: void run() { safeOut out(cout); _str += ' '; for(int i=0; i<10; i++) { _str += '.'; out << _str; } } void setString(const string &s) { _str = s; } private: string _str; }; class proc2 { public: void run() { safeOut out(cout); for(int i=0; i<10; i++) out << _str; } void setString(const string &s) { _str = s; } private: string _str; }; void main() { cout << "\n Demonstrating generic thread class " << "\n ====================================\n"; cout.flush(); safeOut out(cout); proc1 p1; p1.setString("\n thread #1: a fairly brief message"); // constructor passes proc1 arg by value, so line below // requires proc1 to support correct copy semantics thread t1(p1); t1.start(); proc2 p2; p2.setString("\n thread #2: shorter message"); // since this thread is created using a proc2 reference // proc2 does not need to support copy semantics, since // no proc2 object is copied - only a reference is copied. thread t2(p2); t2.start(); t1.wait(); t2.wait(); out << "\n\n"; } #endif