【发布时间】:2013-05-27 22:57:06
【问题描述】:
考虑如下代码sn-p:
#import <pthread.h>
#import <stdio.h>
#import <sys/epoll.h>
#import <sys/eventfd.h>
#import <unistd.h>
int epollfd;
int evntfd;
void *function(void *arg) {
struct epoll_event events;
while(1) {
int c = epoll_wait(epollfd, &events, 1, -1);
if(c != -1) {
printf("%d\n", c);
break;
}
}
return NULL;
}
int main() {
evntfd = eventfd(0, 0);
epollfd = epoll_create(0);
struct epoll_event evnt = { 0 };
evnt.data.fd = evntfd;
evnt.events = EPOLLIN | EPOLLET;
epoll_ctl(epollfd, EPOLL_CTL_ADD, evntfd, &evnt);
pthread_t thread;
pthread_create(&thread, NULL, &function, NULL);
sleep(1);
unsigned long int u = 7;
write(evntfd, &u, sizeof(unsigned long int));
sleep(1);
return 0;
}
write() 不应该让epoll_wait 返回一个不同于-1 的值吗?当我编译上面的代码并运行它时,什么都没有打印出来......
【问题讨论】: