我的简化版的LF线程池(领导者与跟随者模式)

    我使劲看了ACE中的LF示例,还是没有看出为什么作者要那么写,我把我简化版的LP线程贴出来,望大家批评批评。
None.gif void  SampleLFTaskPool::start( const   char *  name, int  count, int  high)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    strncpy(threadName,name,
19);
InBlock.gif    
this->msg_queue()->high_water_mark(high);
InBlock.gif    
this->activate(THR_NEW_LWP|THR_JOINABLE,count);
ExpandedBlockEnd.gif}

None.gif
void  SampleLFTaskPool::svc()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
while(!bExit_)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        ACE_Message_Block
* mb=0;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            ACE_GUARD(ACE_Thread_Mutex,mon,lock_);
InBlock.gif            
if(getq(mb) <-1)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                ACE_DEBUG((LM_ERROR,ACE_TEXT(
"%s Exited:%p"),threadName));
InBlock.gif                
break;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        pro(mb);
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
void  SampleLFTaskPool::stop()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    bExit_ 
= true;
ExpandedBlockEnd.gif}
头文件
None.gif class  SampleLFTaskPool: public  ACE_Task < ACE_MT_SYNCH >
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif {
InBlock.gif    
public:
InBlock.gif        SampleLFTaskPool(
void);
InBlock.gif        
~SampleLFTaskPool(void);
InBlock.gif    
public:
InBlock.gif        
virtual int start(const char* name,int count,int high);
InBlock.gif        
virtual int svc (void);
InBlock.gif        
virtual void pro(ACE_Message_Block* mb);
InBlock.gif        
virtual int stop();
InBlock.gif        
InBlock.gif        
char                    threadName[20];
InBlock.gif        ACE_Thread_Mutex        lock_;                        
bool                    bExit_;                // 是否退出
ExpandedBlockEnd.gif
    }
;

转载于:https://www.cnblogs.com/tionase/archive/2006/09/02/493036.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值