lundi 28 août 2017

Threads - Mac vs Linux

Great!

I just finished my implementation on Mac with g++ / clang

Configured with: --prefix=/Applications/http://ift.tt/1d5DwEL --with-gxx-include-dir=/Applications/http://ift.tt/2h6IoD1
Apple LLVM version 8.1.0 (clang-802.0.42)
Target: x86_64-apple-darwin16.7.0
Thread model: posix

and tested my code on linux

g++ (Debian 4.7.2-5) 4.7.2

running a relatively simple threading operation. What worked on mac, fails on linux now with :

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)));
            }

with the thread function defined as. Adding prints into compute it does not jump into the function at all... Any idea why this happens?

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){

I am compiling with

g++ -Wall main.cpp -o matrix.exe -std=c++11

but get the above runtime error. Any ideas how to fix this? I use std libraries only, nothing fancy...

Aucun commentaire:

Enregistrer un commentaire