zhtread c++多线程库的使用3

今天公司请客吃饭 回来较晚  少些一点

1关于线程优先权的问题
若有线程优先权 那么在使用的时候线程调度器就倾向于优先执行级别较高的线程

  1. #include <zthread/runnable.h>
  2. #include <zthread/Thread.h>
  3. #include <iostream>
  4. #pragma comment(lib,"ZThread_Z.lib")
  5. class thread : public ZThread::Runnable
  6. {
  7. public:
  8.     thread(int _id): id(_id){}
  9.     ~thread(){}
  10.     void run()
  11.     {
  12.          int i =0 ;
  13.          while(i++<100)
  14.         {
  15.               printf("i am thread: %d ./n", id); 
  16.               //_sleep(1200);
  17.         }
  18.  
  19.         ZThread::Thread::yield ();
  20.         printf(" i am  occur/n");
  21.     }
  22. private:
  23.     int id;
  24. };
  25. int _tmain(int argc, _TCHAR* argv[])
  26. {
  27.       try
  28.       {
  29.           ZThread::Thread exetor(new thread(1));
  30.           exetor.setPriority(ZThread::High);
  31.          
  32.            for(int i=0;i<10;i++)
  33.           {
  34.                ZThread::Thread exetor(new thread(1));
  35.                exetor.setPriority(ZThread::Low);
  36.           }
  37.            printf("start /n");
  38.       }
  39.       catch(ZThread::Synchronization_Exception& e)
  40.       {
  41.             printf("%s",e.what());
  42.       }
  43.       _sleep(20000);
  44.       return 0;
  45. }
当然也可以使用get Priority()获取线程优先级

当然优先级的概念并不保证低优先级的线程不会被执行 而是指执行的可能较小而已
 
晚了  明天再边看边写  写完也就学完了

不是这样吗

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值