using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
7:
namespace SynchronizationSamples
9: {
class SharedState
11: {
int state = 0;
object();
int State
15: {
return state;}
value; }
18: }
19:
int IncrementState()
21: {
ref state);
23:
24: }
25: }
26:
class Job
28: {
29: SharedState sharedState;
public Job(SharedState sharedState)
31: {
this.sharedState = sharedState;
33: }
34:
void DoTheJob()
36: {
int i = 0; i < 50000;i++ )
38: {
39: sharedState.IncrementState();
40: }
41: }
42: }
class Program
44: {
string[] args)
46: {
int numTasks = 20;
new SharedState();
new Task[numTasks];
50:
int i = 0; i < numTasks; i++)
52: {
new Job(state).DoTheJob);
54: tasks[i].Start();
55: }
56:
int i = 0; i < numTasks;i++ )
58: {
59: tasks[i].Wait();
60: }
,state.State);
62: Console.Read();
63: }
64: }
65: }