I am learning threads right now in school, and we had to write a program that used multiple threads, however, it did not work properly until I used thread.join()
It works like it should now, but I am not entirely sure what is happening.
Originally I had something like this. It caused the output of the threads to conflict with one another.
t1.start();
t2.start();
t3.start();
I then did this, and the output was fine and the correct answer was achieved.
t1.start();
t1.join();
t2.start();
t2.join();
t3.start();
t3.join();
My question is, what is happening in the first example compared to the second? I've been googling and searching on stackoverflow, but can not seem to find an answer that completely helps me understand.