小编jcm*_*jcm的帖子

使用clang 8的lambda表达式中的双重释放崩溃

当将std :: vector移至lambda表达式中并引发lambda表达式时,我在使用lang 8.0时遇到双重崩溃。其他编译器(例如gcc或clang 7)的可执行文件正在运行,没有错误。

我在代码中做非法行为吗?

template<typename F>
void myExecute(F&& f)
{
    f();
}

int main()
{
    try {
        std::vector<double> test = {0.0, 1.0};
        myExecute([v = std::move(test)]() {
            throw std::runtime_error("exception");
        });
    }
    catch (const std::exception& e) {
        std::cout << e.what() << std::endl;
    }
}
Run Code Online (Sandbox Code Playgroud)

在魔盒中尝试

c++ clang

8
推荐指数
1
解决办法
92
查看次数

C++ 11中的并发阻塞队列

对于在线程之间传递消息,我正在寻找具有以下属性的并发队列:

  • 有限的大小
  • 阻止/等待元素可用的pop方法.
  • 中止取消等待的方法
  • 可选:优先

多个生产者,一个消费者.

concurrent_bounded_queueTBB会提供,但我正在寻找替代方案,以避免TBB的额外的依赖.

该应用程序使用C++ 11和boost.我在找不到任何合适的东西.有什么选择?

concurrency c++11

5
推荐指数
1
解决办法
3614
查看次数

使用 helgrind 提升 asio http async_client 示例警告:误报?

helgrind中运行官方boos asio示例代码的http async_client示例时,出现警告。文件中的这段代码boost/asio/detail/posix_event.hpp似乎是警告的原因:

// Signal the event and unlock the mutex.
template <typename Lock>
void signal_and_unlock(Lock& lock)
{
    BOOST_ASSERT(lock.locked());
    signalled_ = true;
    lock.unlock();
    ::pthread_cond_signal(&cond_); // Ignore EINVAL.
}
Run Code Online (Sandbox Code Playgroud)

这是 valgrind/helgrind 的完整输出:

jcm@Ubuntu:~/samples/async-client/build$ valgrind --tool=helgrind ./async-client stackoverflow.com error.html
==2894== Helgrind, a thread error detector
==2894== Copyright (C) 2007-2011, and GNU GPL'd, by OpenWorks LLP et al.
==2894== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==2894== Command: ./async-client stackoverflow.com error.html
==2894== 
==2894== ---Thread-Announcement------------------------------------------
==2894== …
Run Code Online (Sandbox Code Playgroud)

c++ valgrind boost-asio

4
推荐指数
1
解决办法
1737
查看次数

标签 统计

c++ ×2

boost-asio ×1

c++11 ×1

clang ×1

concurrency ×1

valgrind ×1