package threadtesting;

public class ThreadB extends Thread {
	
	/* variables */
	Data data;
	int [] C;
	
	/* constructor */
	public ThreadB(Data data) {
		this.data = data;
	}
	
	/* Method's */
	
	@Override
	public void run() {		
		/* initialization */
		System.out.println("Ïîò³ê2: Ââ³ä äàíèõ!");
		data.C = data.generateArray(3);
		data.B = data.generateArray(4);
		data.MX = data.generateMatrix(2);
		
		data.PrintB();
		data.PrintC();
		data.PrintMX();
		
		/* send signal to Thread1 */
		data.initializationDataProcessInThread2Finished();
		
		data.waitForThread1CopyC();
		C = data.getCopyOfC();
		data.thread2CopiedC();
		 
		int tmp;
		for(int i=data.getSize()/2;i<data.getSize();i++) {
			tmp=0;
			for(int j=0;j<data.getSize();j++) {
				tmp+=C[j]*data.MX[j][i];
			}
			data.A[i] = tmp + data.B[i];
		}
		
		data.calculationProcessInThread2Finished();
	}

}
