I understand a synchronized block or method will block all threads until the one inside has "left". I am wondering, can context switching happen when thread is executing inside synchronized block? In my understanding, it shouldn't.
Thanks!
can context switching happen when thread is executing inside synchronized block?
Yes, a context switch can happen inside a synchronized
block as well. The only thing that's going to be different is that no other thread would be able to enter the same synchronized
block (or any other block synchronized
on the same object) until the context switches back to that pre-empted thread, letting it finish with its protected code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With