Mac Mini M1上MacOSX Sleep系统调用异常问题求助
Mac Mini M1上sleep调用出现随机延迟问题
在Mac Mini M1上运行服务时,白天多次出现几秒到20分钟的莫名随机延迟,该服务在Linux上运行完全正常。疑似macOS的Sleep系统调用存在严重问题。这台机器未运行其他程序,仅安装了少量开发工具,未连接屏幕和键盘。
最小复现案例
#include <iostream> #include <thread> #include <chrono> int main() { for (;;) { std::this_thread::sleep_for(std::chrono::seconds(10)); const auto now = std::chrono::system_clock::now(); std::cout << "Wall clock: " << now << std::endl; } }
异常延迟示例
本该休眠10秒却休眠了15分钟的情况多次出现,日志如下:
Wall clock: 2024-07-02 05:34:08.577015 Wall clock: 2024-07-02 05:34:18.705682 Wall clock: 2024-07-02 05:34:28.853954 Wall clock: 2024-07-02 05:50:42.539091 Wall clock: 2024-07-02 05:50:52.582264
launchd配置文件
通过launchd运行测试程序的plist配置:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>localhost.sleep_test</string> <key>Program</key> <string>/usr/local/bin/sleep_test.sh</string> <key>RunAtLoad</key> <true/> <key>StandardOutPath</key> <string>/Users/user/sleep_test-output.txt</string> <key>StandardErrorPath</key> <string>/Users/user/sleep_test-errors.txt</string> </dict> </plist>
启动命令
% launchctl load localhost.sleep_test.plist % launchctl start localhost.sleep_test
系统与编译器信息
系统版本
% uname -a Darwin MacMini 23.5.0 Darwin Kernel Version 23.5.0: Wed May 1 20:16:51 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T8103 arm64
编译器版本
% clang --version Apple clang version 15.0.0 (clang-1500.3.9.4) Target: arm64-apple-darwin23.5.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
内容的提问来源于stack exchange,提问作者VargaD
相关产品推荐
相关产品推荐

