Probleme beim Übergeben des Arrays als Verweis auf Threads

Ich lerne Threading und habe einige einfache Beispiele gefunden.

Was ich hoffe zu tun ist, erstellen Sie 5 Threads, die jeweils eine Zufallszahl zu einem Array von 20 Int. Zuweisen. Dann haben Sie endlich weitere 5 Threads, die dieses Array zu einem größeren int von 100 rekonstruieren.

Hier ist ein früherer Code, den ich versucht habe. Ich hatte gehofft, ohne Glück ein Array als Referenz übergeben zu können.

Irgendwelche Ideen wären willkommen, bitte bedenke, ich bin völlig neu in Threads

#include <process.h>
#include <windows.h>
#include <iostream>
#include <fstream>
#include <time.h>
//#include <thread>

using namespace std;

void myThread (void *dummy );
void myThread2 (void *dummy );

int main()
{

    ofstream myfile;
    myfile.open ("coinToss.csv");

    int rNum;

    long numRuns;
    long count = 0;
    int divisor = 1;
    float holder = 0;
    int counter = 0;
    float percent = 0.0;

    int array1[1000000];
    int array2[1000000];


    srand ( time(NULL) );

    printf ("Runs (use multiple of 10)? ");
    cin >> numRuns;

    for (int i = 0; i < numRuns; i++)
    {
        _beginthread( myThread, 0, (void *) (array1) );
        _beginthread( myThread2, 0, (void *) (array2) );

    }

}

void myThread (void *param )
{
    int i = *(int *)param;

    for (int x = 0; x < 1000000; x++)
    {
        //param[x] = rand() % 2 + 1;
        i[x] = rand() % 2 + 1;
    }

}

void myThread2 (void *param )
{
    int i[1000000] = *(int *)param;

    for (int = 0; x < 1000000; x++)
    {
        i[x] = rand() % 2 + 1;
    }

}

Antworten auf die Frage(3)

Ihre Antwort auf die Frage