日期:2014-05-16  浏览次数:20697 次

pthread 的问题


void WaitEvent()
        {
            pthread_cond_wait(&st_csCondWait,&st_csMutex);
            pthread_mutex_lock(&st_csMutex);
        }
        void ActiveEvent()
        {
            pthread_cond_signal(&st_csCondWait);
            pthread_mutex_unlock(&st_csMutex);
        }



我封装了下,有时候无法激活 多线程的时候会死锁,是不是不能这样用?

------解决方案--------------------
...当然不能这样用啊...

       void WaitEvent()
        {
            pthread_mutex_lock(&st_csMutex);
            pthread_cond_wait(&st_csCondWait,&st_csMutex);
            pthread_mutex_unlock(&st_csMutex);
        }
        void ActiveEvent()
        {
            pthread_cond_signal(&st_csCondWait);
        }

pthread_cond_wait的时候会释放锁,当这个函数返回的时候回重新加锁.