Witam
Zgodnie z radą, żeby zamiast używać _beginthread
oraz castowania na void*
zacząłem używać std::thread
.
Większość funkcji działa tak jak powinna, jednak w momencie próby stworzenia wątku z funkcji, która jako parametr zawiera strukturę pojawia się poniższy błąd oraz otwiera plik Microsoft Visual Studio 2012\VC\crt\src\intel\chkstk.asm
.
Unhandled exception at 0x00CB0677 in Projekt na konkurs Interaktywny produkt IT.exe: 0xC00000FD: Stack overflow (parameters: 0x00000000, 0x002E2000).
Ten kod działa poprawnie:
#include <array>
#include <thread>
...
const short int w = 100;
const short int h = 200;
struct Coord{
short int CX;
short int CZ;
short int X;
short int Y;
short int Z;
};
struct WWR{
short int X;
short int Y;
short int Z;
short int R;
short int K;
short int Power;
};
struct WySK{
short int Beg;
short int Large;
double P;
bool NewBlock;
Coord End;
};
struct WWL{
short int X;
short int Y;
short int Z;
short int R;
short int Power;
double C;
WySK LPr;
};
struct Chunk{
short int epolx;
short int epolz;
bool Rd;
std::array <std::array <std::array <short int, w>, h>, w> ty;
std::array <std::array <std::array <short int, w>, h>, w> tK;
std::array <std::array <std::array <short int, w>, h>, w> tS;
std::array <std::array <std::array <short int, w>, h>, w> tR;
std::array <std::array <std::array <short int, 2>, h>, w> Map;
std::vector <WWR> WR;
std::vector <WWL> WL;
std::vector <WWL> WLE;
};
std::array <std::array <Chunk, 3>, 3> Ub;
short int XYZ;
void xyz (short int XpostacX, short int ZpostacZ){
XYZ++;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
GenBT = std::thread (xyz, 0, 0);
...
}
Przy tym kodzie pojawia się opisany powyżej błąd:
#include <array>
#include <thread>
...
const short int w = 100;
const short int h = 200;
struct Coord{
short int CX;
short int CZ;
short int X;
short int Y;
short int Z;
};
struct WWR{
short int X;
short int Y;
short int Z;
short int R;
short int K;
short int Power;
};
struct WySK{
short int Beg;
short int Large;
double P;
bool NewBlock;
Coord End;
};
struct WWL{
short int X;
short int Y;
short int Z;
short int R;
short int Power;
double C;
WySK LPr;
};
struct Chunk{
short int epolx;
short int epolz;
bool Rd;
std::array <std::array <std::array <short int, w>, h>, w> ty;
std::array <std::array <std::array <short int, w>, h>, w> tK;
std::array <std::array <std::array <short int, w>, h>, w> tS;
std::array <std::array <std::array <short int, w>, h>, w> tR;
std::array <std::array <std::array <short int, 2>, h>, w> Map;
std::vector <WWR> WR;
std::vector <WWL> WL;
std::vector <WWL> WLE;
};
std::array <std::array <Chunk, 3>, 3> Ub;
short int XYZ;
void xyz (short int XpostacX, short int ZpostacZ, Chunk UN){
XYZ++;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
GenBT = std::thread (xyz, 0, 0, Ub[1][1]);
...
}
Korzystam z programu Microsoft Visual Studio 2012, v110, windows 7.