Skip to main content
edited tags
Link
Raphael
  • 72.9k
  • 30
  • 181
  • 393
edited title
Link
Juho
  • 22.8k
  • 7
  • 62
  • 117

confused about threads If a thread containing main terminates, can another thread do anything?

Source Link
y0n1
  • 43
  • 4

confused about threads

I'm studying threads in C and I have this theoretical question in mind that is driving me crazy. Assume the following code:

1) void main() {
2)     createThread(...); // create a new thread that does "something"
3) }

After line 2 is executed, two paths of execution are created. However I believe that immediately after line 2 is executed then it doesn't even matter what the new thread does, which was created at line 2, because the original thread that executed line 2 will end the entire program at its next instruction. Am I wrong? is there any chance the original thread gets suspended somehow and the new thread get its chance to do something (assume the code as is, no sync between threads or join operations are performed)