Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Use Lock Keyword
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 // //======================================================= // Code Examples from Exam Ref 70-483 //======================================================= // //AUTHOR: Wouter de Kort // //PURPOSE: Synchronizing Resources // //SECTION: Objective 1.2 - Chapter 1 // //MODIFICATION HISTORY //DATE NAME DESCRIPTION //----------- ---------------- -------------------- //10/19/2017 Cristian Canedo Initial commit //10/19/2017 Cristian Canedo Use lock keyword //======================================================= using System; using System.Threading; using System.Threading.Tasks; namespace Rextester { public class Program { ///<summary> /// EXPECTED: Ouput will always be 0 because there is no /// way one thread can change the value while the other /// thread is working with it ///</summary> public static void Main(string[] args) { int number = 0; object _lock = new object(); var up = Task.Run(() => { for (int i = 0; i < 1000000; i++) { lock (_lock) number++; } }); for (int i = 0; i < 1000000; i++){ lock (_lock) number--; } up.Wait(); Console.WriteLine(number); } } }
run
|
edit
|
history
|
help
0
4
test
n th to last element
test using C#2019
sdfrgthyjuytrfdf
KeyValue pair C#
Sum of numbers in string
bbbbbb
Калькулятор
Danny Garcia vs. Jose Benavidez Jr Live Stream