Bonjour,

J'ai écrit un programme très simple qui construit 2 threads. Chacun appelle une fonction qui affiche la valeur passée en paramètre. En revanche je ne comprends pas pourquoi les deux threads affichent la parfois même valeur pour le paramètre. Voici le code :

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
 
pthread_t pthread1, pthread2;
 
void * f( int * i )
{
	printf("Param -> %d\n", *i);
}
 
int main( int argc, char ** argv )
{
	int i = 0;
	pthread_create(&pthread1, NULL, (void *)f, &i);
	i = 1;
	pthread_create(&pthread2, NULL, (void *)f, &i);
 
	pthread_exit(0);
 
	return EXIT_SUCCESS;
}
Merci d'avance à ceux qui pourront m''aider pour pouvoir faire afficher un paramètre différent à chaque appel .


Nico.