3
我刚刚完成我的Mac上实现与g++/clang
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
编译但得到上述运行时错误。任何想法如何解决这一问题?我只用STD库,没有什么花哨......
是的,工作。谢谢!那么,为什么linux需要pthread而mac可以处理没有? –