Scrigroup - Documente si articole

     

HomeDocumenteUploadResurseAlte limbi doc
AccessAdobe photoshopAlgoritmiAutocadBaze de dateCC sharp
CalculatoareCorel drawDot netExcelFox proFrontpageHardware
HtmlInternetJavaLinuxMatlabMs dosPascal
PhpPower pointRetele calculatoareSqlTutorialsWebdesignWindows
WordXml

AspAutocadCDot netExcelFox proHtmlJava
LinuxMathcadPhotoshopPhpSqlVisual studioWindowsXml

The Interlocked Class

c



+ Font mai mare | - Font mai mic



The Interlocked Class

Interlocked synchronizes access to an integer variable that is being shared by a number of threads. The operation is carried out in an atomic manner. Let's see an example, WroxInterlocked.cs:



using System;
using System.Threading;

namespace WroxInterlocked

Thread.CurrentThread.GetHashCode () , i);



public class MainApp

mR.WaitOne(10000, true);



The output for WroxInterLocked is:

Thread ID = 2 Count = 1
Thread ID = 2 Count = 2
Thread ID = 2 Count = 3
Thread ID = 2 Count = 4
Thread ID = 2 Count = 5
Thread ID = 2 Count = 6
Thread ID = 2 Count = 7
Thread ID = 2 Count = 8
Thread ID = 2 Count = 9
Thread ID = 2 Count = 10

WroxInterLocked shows the use of the Interlocked class. We increment the value of the global variable i in an atomic manner. Like the Increment() method, there is also a Decrement() method that reduces the value of a variable by one. In the same manner, the Exchange() method changes the value of two variables passed to it as ByRef parameters.



Politica de confidentialitate | Termeni si conditii de utilizare



DISTRIBUIE DOCUMENTUL

Comentarii


Vizualizari: 709
Importanta: rank

Comenteaza documentul:

Te rugam sa te autentifici sau sa iti faci cont pentru a putea comenta

Creaza cont nou

Termeni si conditii de utilizare | Contact
© SCRIGROUP 2024 . All rights reserved