3
素晴らしい!スレッド - Mac vs Linux
私はちょうど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
とMac上で私の実装を完了し、Linuxの比較的単純なスレッドの操作を実行している
g++ (Debian 4.7.2-5) 4.7.2
に自分のコードをテストしました。定義されたスレッド機能付き
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)));
}
:Mac上で働いていた何を、と今Linux上で失敗します。 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
でコンパイルするが、上記のランタイムエラーを取得しています。任意のアイデアをどのようにこれを修正するには?私は
g++ -Wall main.cpp -o matrix.exe -pthread -std=c++11
は、この情報がお役に立てば幸い、以下のコマンドを試してください、あなたが適切にpthreadをリンクされていません
はい、うまくいきました。ありがとうございました!だから、なぜMacはpthreadを必要とするのですか? –