- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我在 Linux 操作系统 + ARM 处理器 + boost 1.51 上运行以下代码。但是,代码没有按预期工作,timed_wait() 调用立即返回。
#include <boost/thread/condition.hpp>
#include <boost/thread/xtime.hpp>
#include <boost/thread/mutex.hpp>
#include <iostream>
using namespace std;
int main()
{
boost::mutex mutex_;
boost::mutex::scoped_lock lock( mutex_ );
boost::xtime xt;
boost::condition condition;
// wait for one second or wait on lock
boost::xtime_get(&xt, boost::TIME_UTC_);
xt.sec += 1;
cout << "Before 1 second wait" << endl;
condition.timed_wait(lock, xt);
cout << "After 1 second wait" << endl;
return 0;
}
在具有相同 ARM 处理器但不同版本的 Linux + glibc + 相同的 boost 1.51 库的其他系统上,代码运行正常并等待 1 秒。
我尝试使用 strace 调试问题。我看到一个不同之处,即在它不工作的系统中没有调用 futex()。
来自代码运行的系统的 strace:
write(1, "Before 1 second wait\n", 21Before 1 second wait) = 21
futex(0xb6fbf0dc, FUTEX_WAKE_PRIVATE, 2147483647) = 0
clock_gettime(CLOCK_REALTIME, {1438150496, 732211544}) = 0
futex(0xbef07a44, FUTEX_WAIT_PRIVATE, 1, {0, 998193456}) = -1 ETIMEDOUT (Connection timed out)
futex(0xbef07a28, FUTEX_WAKE_PRIVATE, 1) = 0
write(1, "After 1 second wait\n", 20After 1 second wait) = 20
来自代码不工作的系统的 strace:
write(1, "Before 1 second wait\n", 21Before 1 second wait) = 21
futex(0xb6fc90dc, FUTEX_WAKE_PRIVATE, 2147483647) = 0
clock_gettime(CLOCK_REALTIME, {1438150407, 134963583}) = 0
futex(0xbe9be988, FUTEX_WAKE_PRIVATE, 1) = 0
write(1, "After 1 second wait\n", 20After 1 second wait) = 20
是否需要更改内核/glibc 才能使此代码正常工作?
最佳答案
与其在使用超时时弄乱时钟,不如使用实际的超时?
condition.timed_wait(lock,boost::posix_time::milliseconds(1000))
这可以防止各种奇怪的问题。
关于c++ - boost - timed_wait 不等待,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31695487/
我创建了一个使用 Executor 框架的程序。我创建了一个定期调度的单个线程。 这里是相同的完整源代码: package com.example; import java.security.Secu
我有一个线程转储,其中有: "http-9443-67" daemon prio=10 tid=0x00007f1d5c37e800 nid=0x10331 runnable [0x00007f1d5
我有一个简单的程序,其中包含触发一些计算的计划任务。 在流程结束时,仍然有很多TIMED_WAITING和WAITING队列,这是我没想到的。 Compute Executor terminated:
我在 Linux 操作系统 + ARM 处理器 + boost 1.51 上运行以下代码。但是,代码没有按预期工作,timed_wait() 调用立即返回。 #include #include #
当在具有持续时间的 boost::condition_variable 上使用 timed_wait 时,等待条件是否会在持续时间后超时,即使用户(或 ntp)更改了系统时间? 例如, boost::
我正在阅读我的 STL 实现(标准问题 g++ 4.6.2)并在 condition_variable 中遇到了这种竞争条件: template cv_status wait_for(unique_l
我正在尝试了解如何使用 timed_wait。我只找到了几个例子( here 和 here )并且在用绝对时间调用它时遇到了问题。下面的代码是一个简化的例子,实际上这一切都发生在一个类中,所以我认为手
我正在开发一个小型线程库,但遇到了问题。 boost::condition_variable.wait() 完美运行,但是 boost::condition_variable.timed_wait()
boost documentation说: Returns: false if the call is returning because the time specified by abs_time
有人有如何最轻松地使用 boost::condition::timed_wait 的示例吗?该主题有一些线程here , here和 here ,但没有一个具有工作示例。而且 boost doc 像往
我们的 tomcat 没有响应任何请求。当我使用“jstack pid”打印堆栈信息时,我得到了以下信息。我发现它在“Thread.sleep(long)”上被阻止。我认为应该是“TIMED_WAIT
我有以下代码来启动 netty 服务器: Application application = ApplicationTypeFactory.getApplication(type);
我想等待一个条件最多 1 秒。我尝试传入 time_duration: boost::posix_time::time_duration td = boost::posix_time::millise
我有 Spring 和 Quartz 作业(集群)定期运行(1 分钟)。当服务器启动时,一切似乎都很好,但一段时间后不会触发作业。重新启动服务器使作业运行,但一段时间后问题再次出现。 我怀疑这是一个线
Java Spring Boot 应用程序请求处于挂起状态,因为线程处于 WAITING 和 TIMED_WAITING 状态。 Jstack 日志: "qtp886341817-1399" #139
以下代码重现了错误: #include #include "boost/thread.hpp" #include "boost/date_time/posix_time/ptime.hpp" int
我们一直在监控 tomcat 7 中的线程,最近我们开始发现线程数有时会变成正常值的两倍,即大约 200 个线程(而不是通常的大约 80 个线程)。 进行线程转储后,我看到在线程数量增加期间,由于存在
例子: boost::interprocess::interprocess_semaphore semDone(0); long sec = 10; boost::posix_time::ptime
我们目前有很多如下形式的代码: boost::xtime t; boost::xtime_get (&t, POV_TIME_UTC); t.sec += 3 ; m_Event.timed_wait
最近我们的一个生产 tomcat 服务器变得没有响应,因为 tomcat 的繁忙线程激增到 200。当我们在重新启动之前进行线程转储时,我们有 100 个线程处于 TIMED_WAITING 状态,就
我是一名优秀的程序员,十分优秀!