Wednesday, February 3, 2016
I ask a few questions about thread inside the critical region of the set
Setting critical region can be used:
Monitor.Enter (this);
// Thread Safety Code (1)
Monitor.Exit (this);
But I like this set up, when debugging still found there two threads simultaneously entered a "thread-safe code (1)" snippet inside, why ah? Wherein the parameters, the significance is not to say that this object before Exit (object) statement calls are not allowed to visit? That is precisely, this function is locked in a code segment or lock an object, for example, if I have another function of this class and there was
Monitor.Enter (this);
// Thread Safety Code (2)
Monitor.Exit (this);
So if I go into a thread-safe code (1), then the thread can not simultaneously enter the security code (2)?
Reply:
Critical area
Advantages, simple, commonly used, easy to implement algorithm
Disadvantages: synchronization overhead is relatively large, the use of critical code segments, it is easy to enter a deadlock state, because they can not set the timeout value while waiting to enter the critical section.
If possible, this should InterlockedIncrement very small overhead of a function.
Reply:
InterlockedIncrement? C # can be used?
Reply:
guanzhu
Reply:
If multiple threads of a multithreaded application defines the critical area, the visual realization of the critical region of the "semantic", if optimistic concurrency semantics, there is no competition between the two critical data areas, the critical region where the two threads can At the same time it enters the critical region. If the serial semantics, whether or not there is competition between the critical area of data, while only one thread to enter the critical region.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment