程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了mach_wait_until() 会被信号中断吗?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决mach_wait_until() 会被信号中断吗??

开发过程中遇到mach_wait_until() 会被信号中断吗?的问题如何解决?下面主要结合日常开发的经验,给出你关于mach_wait_until() 会被信号中断吗?的解决方法建议,希望对你解决mach_wait_until() 会被信号中断吗?有所启发或帮助;

sleep() 可能比指定的更早工作,因为它可以被信号唤醒。

手册页说明:

sleep() 函数会暂停调用线程的执行,直到经过了几秒 或将信号传递给线程 并且其操作是调用信号捕获函数或终止线程或进程。

@H_184_3@mach_wait_until() 没有手册页。它也可以被信号中断吗?在旧的 Apple 邮件列表帖子中,有人声称不会,但我遇到了一种情况,只有这样做才有意义。是否在任何地方都有记录,或者是否有人对此主题有更多见解?

解决方法

看起来可以。

当然没有文档,这不是 Apple 编写文档的方式。

不过还好,我们可以用苹果开源的xnu内核进行检查: https://opensource.apple.com/source/xnu/xnu-7195.81.3/

我想说我们在文件 xnu-7195.50.7.100.1\osfmk\kern\clock.c 中很有趣 有一个陷阱通过这样的调用实现了 mach_wait_until:

wresult = assert_wait_deadline_with_leeway((event_t)mach_wait_until_trap,THREAD_ABORTSAFE,TIMEOUT_URGENCY_user_NORMAL,deadline,0);

这里的 THREAD_ABORTSAFE 在 xnu-7195.50.7.100.1\osfmk\kern\kern_types.h 中声明,并附有一些有用的注释:

* THREAD_ABORTSAFE:
 *    Wait will end if someone explicitly wakes up the thread,the wait timeout
 *    expires,the current thread is being terminated,if any signal arrives for
 *    the task,or thread_abort_safely() is called on the thread.
 *
 *    Using this value means that you are willing to bE interrupted in the face
 *    of any user signal,and safely rewind the thread BACk to the user/kernel
 *    boundary.  Many syscalls will try to restart the operation they were performing
 *    after the signal has been handled.
 *
 *    You must provide this value for any unbounded wait - otherwise you will
 *    pend user signals forever.

大佬总结

以上是大佬教程为你收集整理的mach_wait_until() 会被信号中断吗?全部内容,希望文章能够帮你解决mach_wait_until() 会被信号中断吗?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: