i'm working on a multy threading app in processing, this is my first result, but is real multythreading or i can obtain something more?
int threads = 2; //numero di threads da creare int n = 10000; particle particles[] = new particle[n];
worker process[] = new worker[threads]; //array di processi Thread threadProcess[] = new Thread[threads]; //array di thread contenente process
void setup(){ background(0); size(400,400); background(0); stroke(255); smooth(); for (int i=0; i<n; i++){ particles[i] = new particle(); } //scorri i thread, e di da dove a dove calcolare (start, stop); for (int i=0, start = 0, stop = n/threads; //inizializza variabili i<threads; //condizione d'uscita i++, start+=stop){ //aggiorna variabili a ogni ciclo process[i] = new worker(); process[i].start = start; process[i].stop = stop; stop += n/threads; threadProcess[i] = new Thread (process[i]); } }
void draw(){ background(0);
for (int i=0; i<threads; i++){ process[i].run(); }
for (int i=0; i<n; i++){ particles[i].draw(); } println(frameRate); }
/*------------------------------*/ class worker implements Runnable{ int start, stop; void run(){ //metodo obbligatorio for (int i=start; i<stop || i<n; i++){//i<n evita di uscire dall'array particles[n] particles[i].update(); } } }
/*------------------------------*/ class particle{ PVector pos = new PVector(random(width),random(height)); PVector vel = new PVector(random(-5,5), random(-5,5));
Hi guys,
i'm understanding deeper the power of java, and after reading this page i've tryed something, but i encounter in a error. i think the code was good, but when i compile receive this error: "The costructor atoms(float,float,float,float) is undefined"
but is defined it in the atoms class!
PS: sometime it works until you saved the sketch, is it a bug?