^{
int eventfd(unsigned int initval, int flags);
我正利用这个调用构造一个在轮询循环中可用的新光剑类。在
Python^{uint64_t
The object contains an unsigned 64-bit integer (uint64_t) counter that is maintained by the kernel.
为什么初始值参数是unsigned int
类型?在
如果我使用非零值作为Lock
的unlocked状态,那么释放是通过编写来完成的。没有介入收购的多个版本是错误的,需要失败。这要求在事件对象包含非零值时写入失败。在它的默认模式下,事件对象将在阻塞写调用之前,添加到它的值,直到(uint64_t)0xfffffffffffffffe
。为了检测这种情况,我将执行非阻塞写入操作,将该值推到该最大值之上,从而触发此情况:
If the addition would cause the counter's value to exceed the maximum, then the write(2) either blocks until a read(2) is performed on the file descriptor, or fails with the error EAGAIN if the file descriptor has been made non‐ blocking.
如果我没听错,你想让这个野兽的状态在}之间交替?在
0
和{初始值的类型可能只是因为历史原因。一旦这样一个接口被使用,它就会被粘住,并且很难在以后更改它。在
如果您需要该值的初始值是}:
UINT64_MAX-1
,为什么不直接用0
参数调用eventfd
,然后在将文件描述符传播给其他任何人之前,立即使用UINT64_MAX-1
执行{(好吧,你会加上错误检查代码,对吧)
相关问题 更多 >
编程相关推荐