Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fundamental difference between Join() Lock()

For the case of both Join() and lock() one thread can execute after the other.What is the main difference?


1 Answers

Lock is a monitor which is used to guarantee that only 1 thread can execute at a time.

lock(myobj)
{
   // only 1 thread here
}

Join is used to wait for a thread to complete, before execution continues.

anotherThread.Join();
// execution here only when anotherThread is complete
like image 73
Andrew Keith Avatar answered May 03 '26 16:05

Andrew Keith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!