Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EventsImp -> int wakeupFds_[2]; 疑问 #26

Closed
Jayhello opened this issue Aug 10, 2017 · 1 comment
Closed

EventsImp -> int wakeupFds_[2]; 疑问 #26

Jayhello opened this issue Aug 10, 2017 · 1 comment

Comments

@Jayhello
Copy link

struct EventsImp {
EventBase* base_;
PollerBase* poller_;
std::atomic exit_;
int wakeupFds_[2];
......
void EventsImp::init() {
int r = pipe(wakeupFds_);

pipe 一般不是进程间通信用的吗?为什么会用在这里呢?有点奇怪,你也没有开多个进程啊?
Channel* ch = new Channel(base_, wakeupFds_[0], kReadEvent);

通过下面来通知读取的对吧?
void wakeup() {
int r = write(wakeupFds_[1], "", 1);
fatalif(r<=0, "write error wd %d %d %s", r, errno, strerror(errno));
}
不是很了解这套流程啊

@dtm-labs
Copy link
Contributor

dtm-labs commented Oct 2, 2017

pipe的经典用法是进程间通信,这里用于线程间通信
epoll或监听各个fd的可读状态,当另一个线程往一个fd写入1字节时,另一个线程的epoll就会返回,就会处理队列中的任务,效果就是唤醒另一个线程,去处理队列中的任务

@Jayhello Jayhello closed this as completed Oct 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant