Timer_create和timerid是允许的吗?
timer_create and timerid, is this allowed?
我不能将evp
参数设置为NULL
,但我想在我的计时器处理程序中接收timerid
,就像它被设置为NULL
一样。我正在考虑打电话:
struct sigevent se;
se.sigev_notify = SIGEV_THREAD;
se.sigev_notify_attributes = {};
se.sigev_notify_function = timer_handler;
timer_create(CLOCK_MONOTONIC, &se, &se.sigev_value);
我不确定,我是否应该这样做,即使它工作。是否有另一种方法来获得timerid
在定时器处理程序,不设置evp
到NULL
?
这肯定是无效的,因为timer_t
可能比int
长。另外,将指针传递给联合类型与将指针传递给联合类型的成员也不一样。
你需要这样做:
timer_t timerid;
struct sigevent se = { 0 };
se.sigev_notify = SIGEV_THREAD;
se.sigev_value.sival_ptr = &timerid;
se.sigev_notify_function = timer_handler;
if (timer_create(CLOCK_MONOTONIC, &se, &timerid) < 0)
abort(); // or whatever
// later...
if (timer_delete(timerid) < 0)
abort();
换句话说,您需要分配空间来容纳timerid
,在sigevent
结构中存放指向它的指针,并在使用完计时器后记得删除它。
还应该经常检查系统调用是否有错误,并做一些事情,而不是像什么都没发生一样继续进行。
相关文章:
- Using C++ CryptAPI:CNG Create CSR
- 错误:(-210:不支持的格式或格式组合)功能'create'中的硬件视频解码器不支持视频源
- Firebase C++VS2018 SDL2-在Firebase::app::create(..)上执行异常处理
- QThread::create 似乎没有将参数传递给函数
- 为什么"non-standard syntax; use '&' to create a pointer to member"在 CTOR 中使用线程?
- QThread::create running on UI Thread
- 空指针(为缺少的输出数组调用的 create() 在 create,文件 /home/m/OpenCV/modules/
- 使用宏替换工厂模式样式 API 中的"create()"函数
- 错误:'create'不是 'cv::Tracker' 的成员
- Gtk::Main 和 Gtk::Application::create 有什么区别?
- 如果它被定义为 C++ 类中的成员函数,我得到了"non-standard syntax; use '&' to create a pointer to member"
- libgit2:git_clone() 失败并出现"failed to create ssl object"错误
- 使用c_str时"Use & to create a pointer to a member"
- OGRE-找不到请求的发射极类型.在promentystemmanager中:: _ create -emitter
- Visual Studio 2015:获取"non standard syntax, use '&' to create a pointer to member"错误
- MinGW在代码块中构建时的ar.exe "could not create temporary file whilst writing archive: no more archived files
- Create Eigen::Ref from std::vector
- B2Shape等于0xCDCDCDCD,并在Create灯具时抛出异常
- QThread 中的 QTcpSocket 将提交事务,但当 Write 被调用时"Cannot create children for a parent that is in a different
- ffmpeg create RTP stream