Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thread.Join vs Thread.State

Thread.Join returns us if the thread has completed. The same we can determine using ThreadState. Then what is the difference between Thread.Join() and Thread.ThreadState?

Can we use them interchangeably?

like image 679
Ram Avatar asked Aug 31 '10 17:08

Ram


2 Answers

The difference between Join and looking at ThreadState manually is that Join is a blocking operation. The function won't return until the timeout is reached or the target Thread completes. Checking the ThreadState is more of a peeking operation.

like image 157
JaredPar Avatar answered Sep 25 '22 02:09

JaredPar


Thread.join WAITS for the thread to complete. ThreadState just gives you a snapshot of the thread and returns without waiting. There's also a variant of Thread.join that takes a time to wait. ThreadState and Join are extremely different and I don't think both can be used interchangeably.

Try doing a test where you do both calls on a thread that has an infinite loop.

like image 27
NG. Avatar answered Sep 25 '22 02:09

NG.