📄 semaphore.cc
字号:
/* $Id: Semaphore.cc,v 1.2 2000/09/24 13:54:53 pure Exp $ */#include "Semaphore.h"Semaphore::Semaphore() : Mutex(){ if (pthread_cond_init(&cond, NULL)) throw; value = 0;} Semaphore::~Semaphore(){ pthread_cond_destroy(&cond);} void Semaphore::signal(int n){ value += n; pthread_cond_signal(&cond);} void Semaphore::wait(){ lock(); while (value <= 0) pthread_cond_wait(&cond, (pthread_mutex_t *) this); value--; unlock();} Semaphore::operator pthread_cond_t* (){ return &cond;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -