Description: Multithreaded C to create three threads, simulation and monitoring operation, create a thread and bind the TestRun method, and displays the thread to allow access to public resources, access to exclusive lock on the synchronization objects, do some time-consuming simulation, demonstrates how to synchronize threads.Please see the following code: private Object obj = new Object ();/ / define synchronization object private int I = 0;/ / integer variables, is used to output shows public void TestRun () / / define the thread binding method {Monitor. Enter (obj);/ / on the synchronization object access to exclusive lock Console. WriteLine (" the initial value of the I: "i.T oString ());Thread.sleep (1000);/ / simulation with some time-consuming work I;/ / variable (I) on the Console. WriteLine (" I after the increase of value is: "i.T oString ());The Monitor. The Exit (obj);/ / out of sync}
To Search:
File list (Click to check if it's the file you need, and recomment it at the bottom):
文件名 | 大小 | 更新时间 |
---|
srcfans.com\UseMonitor\UseMonitor\Program.cs | 1351 | 2016-12-31
|
srcfans.com\UseMonitor\UseMonitor\Properties\AssemblyInfo.cs | 1360 | 2010-09-07
|
srcfans.com\UseMonitor\UseMonitor\UseMonitor.csproj | 2493 | 2010-09-07
|
srcfans.com\UseMonitor\UseMonitor.sln | 920 | 2010-09-07
|
srcfans.com\UseMonitor\UseMonitor.suo | 11264 | 2010-09-07
|
srcfans.com\UseMonitor\UseMonitor\Properties | 0 | 2016-12-31
|
srcfans.com\UseMonitor\UseMonitor | 0 | 2016-12-31
|
srcfans.com\UseMonitor | 0 | 2016-12-31
|
srcfans.com | 0 | 2016-12-31 |