📄 demo_thread.cpp
字号:
/* Copyright is licensed under GNU LGPL. by I.J.Wang 2003 Build: make demo_thread*/#include "../src/wy_thread.h"#include "../src/wytimespec.h"#include "../src/wy_uty.h" // Class Thread inherits Wy_Thread, is a simple thread object for demo. // class Thread : public Wy_Thread { WyTimeSpec dtime; // delay time public: Thread() : dtime("1.5") /*1.5 seconds*/ {}; ~Thread() throw() { tmain_close(); // stop a possibly active thread }; protected: WyRet tmain(void) { // reimplement the default tmain() // loop 5 times: sleep and print 'Z' for(int i=0; i<5; ++i) { Wy::sleep(dtime); Wy::cerr << 'Z'; } return(Ok); }; }; int main(void) try { WyRet r; Thread thrd; // declare a Thread object // begin a new thread to run thrd.tmain() if((r=thrd.begin())!=Ok) { WY_THROW(r); } // wait until thread state is not Active if((r=thrd.wait_not(Wy_Thread::Active))!=Ok) { WY_THROW(r); } return(0); } catch(const WyRet& e) { Wy::cerr << Wy::wrd(e) << '\n'; throw; } catch(...) { Wy::cerr << "Unidentified throw object\n"; throw; };
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -