Here when I execute the program, the output I'm getting on all the tries is 342 (naturally first 34 prints together then 2 seconds later 2 prints). My doubts is that is the order of start() [x.start() followed by y.start()] important in order of execution? Shouldn't the output be 234?
P.S. If I alter the start() to y.start() followed by x.start(), then also the output is 342.
No, it's not important. You have no control/knowledge of how those two threads will be scheduled; they have the same priority as each other and the thread from which you are starting them - eg it will depend on how many processors you have in your machine. If you need a predictable behaviour you will need to use semaphores or somesuch to synchronise them.
as JamesCherrill says, you don't control it. of course, when they are using (and changing) the same values, you may want to make sure that the thread that starts first, completes the tasks on those variables, before the second one kicks in.
synchronization can help you there.
Need some help with this Array. I am trying to get the sum of the even numbers and the sum of the odd numbers using a for each loop. I know the answers to what I am trying to achive are sum of even = 84 and the sum of ...
I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...