I will explain my understanding of C # blocking as follows, please help me check if I understand this correctly.
public class TestLock { private object threadLock = new object(); ... public void PrintOne() { lock (threadLock) {
Case I> Thread1 and Thread2 simultaneously try to call PrintOne. Since PrintOne is protected by instance locking, at any time, only one thread can go exclusively to the One section.
Is it correct?
Case II> Thread1 and Thread2 simultaneously try to call PrintOne and PrintTwo, respectively (i.e. Thread1 calls PrintOne and Thread2 calls PrintTwo) Since the two printing methods are protected by the same instance lock at any time, only one thread can exclusively access the section SectionOne or SectionTwo, but NOT both.
Is it correct?
multithreading c # locking
q0987
source share