Bonjour,
Veuillez examiner ce code avec moi, et me dire pourquoi la variable var garde sa valeur initiale apres l'avoir modifiée dans un thread !
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class MyClass
{
	private Thread th1;
	private Thread th2;
 
	private int var;
 
	public static main()
	{
		th1 = new Thread(new ThreadStart(funTh1));
		th1.Start();
	}
 
	private void funTh1()
	{
		var = 1;
		th2 = new Thread(new ThreadStart(funTh2));
		th2.Start();
		////NORMALEMENT SUR CETTE LIGNE : var = 2 !! ce qui n'est pas le cas !
	}
 
	private void funTh2()
	{
		var = 2;
	}
}