目录
为了后续模块的书写,需要使用到该函数,故在此介绍
函数介绍
大致介绍,以及常规使用参数
测试代码
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/eventfd.h>
int main()
{
// 第二参数前者禁止复制,当有子进程的时候会出现这种情况,后者启动非阻塞
int efd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
if (efd < 0)
{
perror("eventfd failed!!");
return -1;
}
uint64_t val = 1; // 规定只能用uint64_t类型的接收
write(efd, &val, sizeof(val));
write(efd, &val, sizeof(val));
write(efd, &val, sizeof(val));
uint64_t res = 0;
read(efd, &res, sizeof(res));
printf("%ld\n", res);
close(efd);
return 0;
}
测试结果,符合预期