We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, I'm new here. My english level is not very high. sorry for that!
I'm not a computer engineer (yet), it's a hobby, because I'm learning.
My PC:
-Core 2 Quad 2,4GHz (4 cores)
-4GB RAM
-Windows 7 64 bit
-Processing 2.2.1
In the last three years I have worked in an allRGB algorithm, and I want to improve that, just for learn:
http://elrincondeabner.blogspot.com.es/2015/05/allrgb.html
http://elrincondeabner.blogspot.com.es/2015/08/allrgb-mediante-algoritmo-genetico.html
I recently managed to apply dithering to my code, and works great!
But until today I have not managed to multithread my code. The code is VERY VERY long, so for simplicity I prefer to work whith a very simpler one. It is the problem:
How to multithread this code and use all of the 4 cores my PC have?
println("Start");
int a=0,b=0,c=0,d=0;
loadPixels();
for (int i=0; i<100000; i++){
a=a+1; //Thread 1
b=b+2; //Thread 2
c=c+3; //Thread 3
d=d+4; //Thread 4
}
updatePixels();
exit();
println("END");
I need the code, please.
Answers
Do you understand the question?
What I want to do is simply make a faster algorithm by using my 4 cores. I searched info but I don't understand/managed how to implement it.
Keep in mind that Processing.js does not support threads at all, so by doing this, you're restricting yourself to only deploying as a Java application.
But the general idea is that you need to isolate each part of your code that can run without affecting other parts of your code. Those isolated parts of your code are things that you might use multithreading for.
Threading is not trivial, and there are any number of ways to use it- some are right, many are wrong. But in keeping with your example, one way to use threads might be something like this:
It's important to note that you have to be absolutely sure that the threads aren't accessing the same data at the same time, otherwise really weird things can happen.
There's a lot more to threading than just this simple example, but these are the basics.
Oh man, Thanks very much!
I will try it :DDDD