|
楼主 |
发表于 2007-12-24 23:13:25
|
显示全部楼层
到今天我已经知道了原因,特发表:
ACE_Thread_Mutex g_mutex;
ACE_Condition<ACE_Thread_Mutex> g_cond(g_mutex);
int g_requestNum = 1;
class CMyTask : public ACE_Task<ACE_MT_SYNCH>
{
public:
CMyTask()
{
}
int svc()
{
ACE_DEBUG((LM_DEBUG,"Thread <%t> enter time: %T\n"));
g_mutex.aquire();
if (g_requestNum < 1)
{
g_cond.wait();
}
--g_requestNum;
g_mutex.release();
ACE_DEBUG((LM_DEBUG,"Thread <%t> exit time: %T\n"));
return 0;
}
int open(void)
{
ACE_DEBUG((LM_DEBUG,"Thread <%t> open!\n"));
this->activate(THR_NEW_LWP | THR_JOINABLE,3);
return 0;
}
int close(u_long flags)
{
ACE_DEBUG((LM_DEBUG,"Thread <%t> close!\n"));
return 0;
}
protected:
private:
};
int main(int argc, char* argv[])
{
CMyTask oCMyTask;
oCMyTask.open();
int sw = 0;
std::cin<<sw;
if (sw == 1)
{
++g_requestNum;
::g_cond.signal();
}
return 0;
} |
|