The CPU can schedule the three threads ( main
/ thread1
/ thread2
) in any order. It might happen that your main
doesn't get a time to run and your threads exit. So, you need to keep keep join
in main
to take care of this case. Scheduling of threads is unpredictable, unless you are using an RTOS
.