什么情况下可以删除事件处理函数的POSIX计时器?

编程入门 行业动态 更新时间:2024-10-11 21:23:23
本文介绍了什么情况下可以删除事件处理函数的POSIX计时器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如果我称之为 create_timer 与 SIGEV_THREAD 常量存储在 sigev_notify 在我的的sigevent 结构字段,那么当定时器事件发生时,我的 sigev_notify_function 回调将会被调用。

If I call create_timer with the SIGEV_THREAD constant stored in the sigev_notify field in my sigevent structure, then when the timer event happens, my sigev_notify_function callback will be called.

是否有任何隐藏的含义或不良的副作用调用 timer_delete 的从我的回调函数中的?

Are there any hidden implications or undesirable side-effects to calling timer_delete from within my callback function?

的具体问题

我最初的想法是,它应该罚款。不过,我不完全理解那些在幕后操作的机制,我很担心回调的线程那里是正确的清除和信号如果定时器的处理和它相关的被删除的结构处理完成之前。

My initial thought was that it should be fine. However, I don't fully understand the mechanics that are operating behind the scenes, and I'm concerned about there being proper cleanup of the callback's thread and handling of the signals if the timer and it's associated structures are removed before handling is complete.

另外一个SO用户问这个问题,它本质上说,我真的需要调用后删除我的定时器 timer_create 我的回答是一个响亮的是然后,他问了一个跟进的评论的问题:什么情况下可以做到这一点从定时器回调函数吗?我没有一个很好的答案。

Another SO user asked this question, which essentially says, "do I really need to delete my timers after calling timer_create? My answer was a resounding yes. He then asked a follow-up question in the comments: "is it okay to do that from the timer callback function?" and I didn't have a good answer to that.

推荐答案

看起来,原则上是不允许调用 timer_create 或 timer_delete ,至少在Linux上。 信号(7)是只允许的异步信号-safe 的功能进行直接或间接的信号处理函数中调用,奇怪 timer_create 和 timer_delete 是未列出在他们之中(也许是一个错字,他们都应该被列为异步信号安全的,因为两者的 timer_create(2)&放大器;的 timer_delete(2)是在手册页第2条,并出现在的系统调用(2))

It looks that in principle it is not allowed to call timer_create or timer_delete, at least on Linux. signal(7) is only allowing async-signal-safe functions to be called directly or indirectly from a signal handler, and strangely timer_create and timer_delete is not listed amongst them (perhaps it is a typo and they both should be listed as async-signal-safe, since both timer_create(2) & timer_delete(2) are in section 2 of the man pages, and appear in syscalls(2))

请注意,POSIX 信号的概念页面没有列出 timer_create 尽可能在信号处理程序。我想,在某些操作系统上,这些定时器功能,可能会完全在C库(而不是在内核中)。

Notice that POSIX signal concepts page does not list timer_create as possible in a signal handler. I imagine that on some operating systems these timer functions might be implemented entirely in the C library (not in the kernel).

我的猜测(因为 timer_create 和 timer_delete 是的 系统调用的 在Linux 中列出< ASM / unistd.h中> )是的 timer_create 和 timer_delete 的其实都是异步-signal安全这样的可以从的Linux 信号处理函数调用的。这可能是在其他POSIX实现假的。

My guess (since timer_create and timer_delete is a syscall on Linux listed in <asm/unistd.h>) is that timer_create and timer_delete are in fact async-signal-safe so can be called from a Linux signal handler. This might be false on other POSIX implementations.

更多推荐

什么情况下可以删除事件处理函数的POSIX计时器?

本文发布于:2023-10-09 05:27:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1474835.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:计时器   函数   情况下   事件   POSIX

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!