#include #include #include double** data; double** result; int dim, steps[] = {0, 0}; double coeff = 0.25; double **input,**output,**temp; pthread_t ts[2]; pthread_attr_t atr; pthread_mutex_t sync_us; pthread_cond_t move_on; void * obrada(void *id){ int tid = (int)id; int i, j; int f = 1; while(f) { for(i=1 + tid;i 0)? 1: 0; //da nisam stigao do kraja? if(steps[tid] < steps[(tid + 1) % 2]){ //sta je sa drugom niti? pthread_cond_wait(&move_on, &sync_us); //ili je cekam pa da radim dalje... } else{ //ili mene cekaju da kompletiram promenu ploca i javim da moze dalje temp = input; input = output; output = temp; pthread_cond_signal(&move_on); } pthread_mutex_unlock(&sync_us); } pthread_exit(NULL); } int main(int argc,char* argv[]) { int i,j; steps[0] = steps[1] = atoi(argv[2]); //broj koraka dim = atoi(argv[1]); dim -= 2; //zaobici ivice data = (double**)malloc((dim + 2)*sizeof(double*)); result = (double**)malloc((dim + 2)*sizeof(double*)); for(i=0;i