今天公司请客吃饭 回来较晚 少些一点
1关于线程优先权的问题
若有线程优先权 那么在使用的时候线程调度器就倾向于优先执行级别较高的线程
当然也可以使用get
Priority()获取线程优先级
当然优先级的概念并不保证低优先级的线程不会被执行 而是指执行的可能较小而已
晚了 明天再边看边写 写完也就学完了
不是这样吗
1关于线程优先权的问题
若有线程优先权 那么在使用的时候线程调度器就倾向于优先执行级别较高的线程
- #include <zthread/runnable.h>
- #include <zthread/Thread.h>
- #include <iostream>
- #pragma comment(lib,"ZThread_Z.lib")
- class thread : public ZThread::Runnable
- {
- public:
- thread(int _id): id(_id){}
- ~thread(){}
- void run()
- {
- int i =0 ;
- while(i++<100)
- {
- printf("i am thread: %d ./n", id);
- //_sleep(1200);
- }
- ZThread::Thread::yield ();
- printf(" i am occur/n");
- }
- private:
- int id;
- };
- int _tmain(int argc, _TCHAR* argv[])
- {
- try
- {
- ZThread::Thread exetor(new thread(1));
- exetor.setPriority(ZThread::High);
- for(int i=0;i<10;i++)
- {
- ZThread::Thread exetor(new thread(1));
- exetor.setPriority(ZThread::Low);
- }
- printf("start /n");
- }
- catch(ZThread::Synchronization_Exception& e)
- {
- printf("%s",e.what());
- }
- _sleep(20000);
- return 0;
- }
当然优先级的概念并不保证低优先级的线程不会被执行 而是指执行的可能较小而已
晚了 明天再边看边写 写完也就学完了
不是这样吗