system_server:condition_variable timed_wait failed: Invalid argument

https://issuetracker.google.com/issues/292138960

异常log:

libc++abi: termination with uncaught exception of type NSt3__112system_errorE: condition_variable timed_wait failed: Invalid argument.

F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
F DEBUG   : Build fingerprint: 
F DEBUG   : Revision: '0'
F DEBUG   : ABI: 'arm'
F DEBUG   : Timestamp: 1970-01-01 00:00:24.108652169+0000
F DEBUG   : Process uptime: 0s
F DEBUG   : Cmdline: system_server
F DEBUG   : pid: 526, tid: 595, name: Thread-5  >>> system_server <<<
F DEBUG   : uid: 1000
F DEBUG   : signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr --------
F DEBUG   : Abort message: 'terminating with uncaught exception of type NSt3__112system_errorE: condition_variable timed_wait failed: Invalid argument'
F DEBUG   :     r0  00000000  r1  00000253  r2  00000006  r3  75f67fc8
F DEBUG   :     r4  75f67fdc  r5  75f67fc0  r6  0000020e  r7  0000016b
F DEBUG   :     r8  75f67fc8  r9  75f67fd8  r10 75f67ff8  r11 75f67fe8
F DEBUG   :     ip  00000253  sp  75f67f98  lr  a33d50c9  pc  a33d50dc
F DEBUG   : backtrace:
F DEBUG   :       #00 pc 000610dc  /apex/com.android.runtime/lib/bionic/libc.so (abort+172) (BuildId: 460a1e81ab9c39eaba7bac395e1f241c)
F DEBUG   :       #01 pc 0001dfb1  /apex/com.android.os.statsd/lib/libstatspull.so (abort_message+92) (BuildId: 961ffc2b332d5bd2f416d2f0e31567de)
F DEBUG   :       #02 pc 000202f3  /apex/com.android.os.statsd/lib/libstatspull.so (demangling_terminate_handler()+142) (BuildId: 961ffc2b332d5bd2f416d2f0e31567de)
F DEBUG   :       #03 pc 0001efcf  /apex/com.android.os.statsd/lib/libstatspull.so (std::__terminate(void (*)())+2) (BuildId: 961ffc2b332d5bd2f416d2f0e31567de)
F DEBUG   :       #04 pc 0001ef87  /apex/com.android.os.statsd/lib/libstatspull.so (std::terminate()+46) (BuildId: 961ffc2b332d5bd2f416d2f0e31567de)
F DEBUG   :       #05 pc 0001e01d  /apex/com.android.os.statsd/lib/libstatspull.so (__clang_call_terminate+4) (BuildId: 961ffc2b332d5bd2f416d2f0e31567de)
I incfs   : Initial API level of the device: 31

Analyze:
1.Through log analysis, the reason for the system error crash is: libc++abi: termination with uncaught exception of type NSt3__112system_errorE: condition_variable timed_wait failed: Invalid argument.
2.Analyze the code and locate the location where the problem occurs:android/frameworks/base/services/incremental/ServiceWrappers.cpp runTimers().
3.Through analysis and experiments, it is initially believed that the problem caused by the parameter "nextJobTs" passed to "mCondition.wait_until" is too large. We divide the initial value of the "static constexpr TimePoint kInfinityTs" by 2 and the problem no longer occurs.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
C++11中引入了condition_variable类,用于实现线程间的同步和通信。condition_variable类提供了wait()和notify()等函数,可以实现类似pthread_cond_wait()和pthread_cond_signal()的功能。 要实现类似pthread_cond_timedwait()的功能,可以结合condition_variable和unique_lock来实现。下面是一个简单的示例代码: ```cpp #include <iostream> #include <thread> #include <mutex> #include <condition_variable> #include <chrono> std::mutex mtx; std::condition_variable cv; bool ready = false; void worker_thread() { std::this_thread::sleep_for(std::chrono::seconds(2)); std::unique_lock<std::mutex> lock(mtx); ready = true; cv.notify_one(); } int main() { std::cout << "Main thread starts." << std::endl; std::thread worker(worker_thread); std::unique_lock<std::mutex> lock(mtx); if (cv.wait_for(lock, std::chrono::seconds(3), []{ return ready; })) { std::cout << "Worker thread signaled." << std::endl; } else { std::cout << "Timeout occurred." << std::endl; } worker.join(); std::cout << "Main thread ends." << std::endl; return 0; } ``` 在上面的示例中,worker_thread函数是工作线程,它会在2秒后将ready标志设置为true,并通过cv.notify_one()通知等待的线程。 在主线程中,我们使用cv.wait_for()函数等待条件变量的通知,等待时间为3秒。如果在等待时间内收到通知,则输出"Worker thread signaled.";如果超过等待时间仍未收到通知,则输出"Timeout occurred."。 注意,在使用condition_variable时,需要结合unique_lock来进行互斥锁的管理,以确保线程安全。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值