Extras din laborator
#include <iostream>
#include <Windows.h>
#include <time.h>
#include <random>
using namespace std;
#define DIMLABIRINT 9 //Dimensiunea labirintului
#define POZSTART DIMLABIRINT / 2
//Matricea care reprezinta labirintul
short labirint[DIMLABIRINT][DIMLABIRINT] = {{1, 0, 1, 1, 1, 0, 1, 0, 0},
{1, 1, 0, 0, 1, 0, 0, 1, 1},
{1, 0, 1, 0, 1, 1, 0, 1, 0},
{1, 0, 1, 1, 1, 0, 0, 0, 1},
{0, 0, 1, 1, 0, 0, 1, 1, 1},
{1, 1, 0, 0, 1, 0, 0, 1, 0},
{0, 0, 1, 0, 0, 1, 0, 0, 1},
{1, 0, 0, 1, 0, 1, 1, 1, 1},
{1, 1, 1, 0, 1, 1, 1, 1, 0}};
//Primul thread
HANDLE thread;
//Mutex-ul pentru controlarea accesului la matrice si la afisare
HANDLE mutex;
typedef struct
{
short i, j;
} Coordonate;
void generareLabirint()
{
//Setam seed-ul pentru functia de generare de nr. aleatoare
srand(time(NULL));
for (short i = 0; i < DIMLABIRINT; i++)
{
short linie[DIMLABIRINT];
for (short j = 0; j < DIMLABIRINT; j++)
{
short val = rand() % 2; //0 sau 1
labirint[i][j] = val;
}
}
labirint[POZSTART][POZSTART] = 0; //Ne asiguram ca primul thread se poate pozitiona in centru
}
void afisareLabirint()
{
for (short i = 0; i < DIMLABIRINT; i++)
{
for (short j = 0; j < DIMLABIRINT; j++)
{
cout << labirint[i][j] << " ";
}
cout << "nn";
}
cout << "------------------------------------------------------n";
}
Conținut arhivă zip
- Threaduri.cpp