FileDocCategorySizeDatePackage
SinTable2.javaAPI DocExample2651Thu Feb 04 16:10:40 GMT 1999None

SinTable2

public class SinTable2 extends Object implements Runnable

Fields Summary
private float[]
lookupValues
private Thread[]
lookupThreads
private int
startLoop
private int
endLoop
private int
curLoop
private int
numThreads
Constructors Summary
public SinTable2()

		lookupValues = new float [360 * 100];
		lookupThreads = new Thread[12];
		startLoop = curLoop = 0;
		endLoop = (360 * 100);
		numThreads = 12;
	
Methods Summary
public float[]getValues()

		for (int i = 0; i < numThreads; i++) {
			lookupThreads[i] = new Thread(this);
			lookupThreads[i].start();
		}
		for (int i = 0; i < numThreads; i++) {
			try {
				lookupThreads[i].join();
			} catch (InterruptedException iex) {}
		}
		return lookupValues;
	
private voidloopDoRange(int start, int end)

		for (int i = start; i < end; i += 1) {
			float sinValue = (float)Math.sin((i % 360)*Math.PI/180.0);
			lookupValues[i] = sinValue * (float)i / 180.0f;
		}
	
private synchronized SinTable2$SinTableRangeloopGetRange()

		if (curLoop >= endLoop)
			return null;
		SinTableRange ret = new SinTableRange();
		ret.start = curLoop;
		curLoop += (endLoop-startLoop)/numThreads+1;
		ret.end = (curLoop<endLoop)?curLoop:endLoop;
		return ret;
	
public voidrun()

		SinTableRange str;
		while ((str = loopGetRange()) != null) {
			loopDoRange(str.start, str.end);
		}