【发布时间】:2018-02-06 09:48:29
【问题描述】:
太棒了!
我刚刚用g++ / clang在Mac上完成了我的实现
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/c++/4.2.1
Apple LLVM version 8.1.0 (clang-802.0.42)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
并在 linux 上测试了我的代码
g++ (Debian 4.7.2-5) 4.7.2
运行一个相对简单的线程操作。什么在mac上有效,现在在linux上失败了:
terminate called after throwing an instance of 'std::system_error'
what(): Operation not permitted
#include <cstddef>
#include <memory>
#include <stdlib.h>
#include <iostream>
#include <thread>
#include <vector>
#include <stdexcept>
std::vector<std::thread> threads;
std::vector<std::tuple<std::size_t, std::size_t>> parts = splitRows(maxNumberThreads, elements);
for (std::size_t threadIndex = 0; threadIndex < maxNumberThreads; threadIndex++)
{
threads.push_back(std::thread(compute<T>,parts[threadIndex], numbers, std::ref(*this),std::ref(other),std::ref(target)));
}
线程函数定义为。将打印添加到compute 它根本不会跳转到函数中......知道为什么会发生这种情况吗?
template<typename T>
void compute(const std::tuple<std::size_t,std::size_t> part,
const std::size_t numbers,
const MyClass<T>& m1,
const MyClass<T>& m2,
MyClass<T>& target){
我正在编译
g++ -Wall main.cpp -o matrix.exe -std=c++11
但得到上述运行时错误。任何想法如何解决这一问题?我只使用标准库,没什么花哨的......
【问题讨论】:
标签: c++ linux multithreading macos c++11