📄 synch-sleep.h
字号:
#include "copyright.h"
#include "thread.h"
#include "list.h"
#include "system.h"
class Lock
{
public:
Lock(char* debugName); //initialize lock be FREE
~Lock(); //析构函数
char* getName() { return name; } //debugging assist
void Acquire(); //wait until the lock is FREE, then set it to BUSY
void Release(); //set lock to be FREE, waking up a thread waiting
//in Acquire if necessary
bool isHeldByCurrentThread(); // true if the current thread
// holds this lock. Useful for checking in Release, and in
// Condition variable ops below
private:
char* name;
Thread *HoldThread;
bool Hold;
List *queue;
};
class Condition
{
public:
Condition(char* debugName); //initialize condition to "no one waiting"
~Condition(); //析构函数
char* getName() { return name; }
void Wait(Lock *conditionLock);
//release the lock, relinquish the CPU until signaled,then re-acquire the lock
void Signal(Lock *conditionLock);
//wake up a thread, if there are any waiting on the condition
void Broadcast(Lock *conditionLock);
//wake up all threads waiting on the condition
private:
char* name;
List *queue;
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -