关于线程的使用

小鱼儿咕噜咕噜 2013-06-25 09:06:01
我最近看国外人写的capwap源码,看到对线程信号和锁等发现他们用的下面的方法,不懂,signal怎么在前面?
pthread_mutex_lock( theMutex )
pthread_cond_signal(theCondition);
pthread_cond_wait(theCondition, theMutex))
pthread_mutex_unlock( theMutex );
...全文
124 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
heartlesstoanyone 2013-06-25
  • 打赏
  • 举报
回复
一个锁当然可以使用前不同的条件变量上
void CSocketEventQueue::WaitEmpty()
{
    CWrapGuard guard(_lock);
    while (0 < _nEvent)
    {
        _emptyCond.Wait(_lock);
    }
}

void CSocketEventQueue::WakeupConsumer()
{
	CWrapGuard guard(_lock);
	if (!_events.empty())
    {
    	_cond.Broadcast();
    }
}

void CSocketEventQueue::WakeupProductor()
{
    CWrapGuard guard(_lock);
	if (0 < _nEvent)
	{
		--_nEvent;
	}
	_emptyCond.Signal();
}
  • 打赏
  • 举报
回复
引用 1 楼 icechenbing 的回复:
看看线程条件变量吧。
具体是下面这样的: pthread_mutex_lock( theMutex ) CWSignalThreadCondition(&gWTPs[selection].interfaceWait); CWWaitThreadCondition(&gWTPs[selection].interfaceComplete, &gWTPs[selection].interfaceMutex); pthread_mutex_unlock( theMutex );
恨天低 2013-06-25
  • 打赏
  • 举报
回复
看看线程条件变量吧。

23,124

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧