私はスレッド化を学んでおり、いくつかの簡単な例を見つけました。
私が望んでいるのは、5 つのスレッドを作成することです。各スレッドは、20 個の int の配列に乱数を割り当てます。最後に、この配列をより大きな 100 サイズの int に再構築する別の 5 つのスレッドを用意します。
ここに私が試していたいくつかの以前のコードがあります。運が悪くても、参照によって配列を渡すことができることを望んでいました。
どんなアイデアでも大歓迎です、覚えておいてください、私はスレッドにまったく慣れていません
#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;
}
}