dimanche 27 janvier 2019

C++ threads and variables

I have a problem within the program that I write. I have functions returning pointers and within the main() I want to run them in threads.

I'm able to execute the functions in threads:

double* SplitFirstArray_1st(double *arr0){
    const UI arrSize = baseElements/4;
    std::cout << "\n1st split: \n";
    double *arrSplited1=nullptr;
    arrSplited1 = new double [arrSize];
    for(UI i=0; i<arrSize; i++){
        arrSplited1 = arr0;
    }

    for(UI j=0; j< arrSize; ++j){
        std::cout << arrSplited1[j] << " ";
        }
    return arrSplited1;
    delete [] arrSplited1, arr0;

}

in main()

std::thread _th1(SplitFirstArray_1st, rootArr);
                _th1.join();

The above is not what I'm after. I have another pointer:

*arrTh1=nullptr;

I would like to use it in a thread so it would be assigned with the value returned by my function SplitFirstArray_1st

arrTh1 = SplitFirstArray_1st(xxx);

Is such action is possible to be executed in a tread ?

Aucun commentaire:

Enregistrer un commentaire