multithreading - .Net Critical regions in threading not working as desired -
I am trying to run a sample code (a very basic one) that involves threading and key areas.
This is my code:
Edit the public static zero zero (object o) {SomeClass example = o some class; Thread.BeginCriticalRegion (); Instance.IsValid = True; Thread.Sleep (2); Instance.IsComplete = true; Thread.EndCriticalRegion (); Instance.print (); }
and I'm calling it as follows:
Private static zero critical hit () {SomeClass instance = new SomeClass (); ParameterizedThreadStart Operation = New ParameteratedThreadStart (Critical Reggon.Ductorialwork); Thread t = new thread (operation); Console.light line ("start thread"); T.Start (example); Thread.Sleep (1); Console "Line thread"; T.Abort (); Console "Light" ("in the main"); Instance.print (); }
However, the output I get is:
**
Start thread Thread start main IsValid: True IsComplete : False
**
Since the important area is defined, IsComplete must be true and should not be mistaken
Does anyone explain this Why can not it work?
There are some classes here for reference:
Public classes some class {private boole_isValid; Public Bull ISIald {Come back; _isValid; } Set {_isValid = value; }} Private B ool _is complete; Public bool isComplete {get {return_isComplete; } Set {_isComplete = value; }} Public Zero Print () {Console.WriteLine ("IsValid: {0}", IsValid); Console.light line ("full clearing: {0}", icecompelt); Console.WriteLine (); Explain with MCTS notes: The idea behind an important area is to provide an area of code that must be implemented. As if it was a single line, any attempt to cancel a thread is within the critical area, as long as the important area is to be finished. At that point, the thread will be revoked, throw ThreadAbortException. The difference between an important area and a thread is shown in the following figure:
"post-text" itemprop = "text"> threads Byte Critical Region did not stop the thread from abrogating. I believe it is used to inform runtime that if the thread is revoked in the Important section, then this application / appdomain is not required to continue running.
There is a more complete description of MSDN documents:
Comments
Post a Comment