Bonjour à tous,

Je suis confrontée à un souci dont je n'ai pas trouvé la solution sur Google : j'ai besoin de créer deux threads dans mon programme :
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
 
        /* diverses initialisations... */
	/* initialize thread_attr structure */
	ret_init_attr = pthread_attr_init(&thread_attr);
	if(ret_init_attr != 0)
	{
		printf("ERROR : insufficient memory to initialize threads' attributes\n");
	}
	ret_init_attr = pthread_attr_setstacksize(&thread_attr,(FSM_Ct_StackSize<PTHREAD_STACK_MIN?PTHREAD_STACK_MIN:FSM_Ct_StackSize));
	if(ret_init_attr != 0)
	{
		printf("ERROR : stack too small: rc=%d\n",ret_init_attr);
	}
 
	/*create first thread */
	ret_init_attr = pthread_create((pthread_t*)(&(AppInfo->ThrNum)), &thread_attr, (void *) fct_thread1, NULL);
	switch(ret_init_attr)
	{
	case 0:
		break;
	case EAGAIN:
		printf("pthread_create : ERROR : not enough memory to create the new thread or system's thread number too big\n");
		break;
	case EINVAL:
		printf("pthread_create : ERROR : invalid argument thread_attr\n");
		break;
	case EPERM:
		printf("pthread_create : ERROR : The caller does not have appropriate permission to set the required scheduling parameters or scheduling policy.\n");
		break;
	default:
		printf("pthread_create : ERROR : unclassified error\n");
	}
 
	/* Creates and starts 2nd thread */
	/* re-initialize thread_attr structure as it may have been modified by pthread_create */
	ret_init_attr = pthread_attr_init(&thread_attr);
	if(ret_init_attr != 0)
	{
		printf("ERROR : insufficient memory to initialize threads' attributes\n");
	}
	ret_init_attr = pthread_attr_setstacksize(&thread_attr,(FSM_Ct_StackSize<PTHREAD_STACK_MIN?PTHREAD_STACK_MIN:FSM_Ct_StackSize));
	if(ret_init_attr != 0)
	{
		printf("ERROR : stack too small: rc=%d\n",ret_init_attr);
	}
 
	ret_init_attr = pthread_create(&ThreadId, &thread_attr, (void *) Thread2, NULL);
	switch(ret_init_attr)
	{
	case 0:
		break;
	case EAGAIN:
		printf("pthread_create : ERROR : not enough memory to create the new thread or system's thread number too big\n");
		break;
	case EINVAL:
		printf("pthread_create : ERROR : invalid argument thread_attr\n");
		break;
	case EPERM:
		printf("pthread_create : ERROR : The caller does not have appropriate permission to set the required scheduling parameters or scheduling policy.\n");
		break;
	default:
		printf("pthread_create : ERROR : unclassified error\n");
	}
Mes threads sont censés boucler indéfiniment, mais dans le doute j'ai quand même défini les pointeurs en argument 1 et 2 de pthread_create (AppInfo->ThrNum, thread_attr et ThreadId) en tant que variables globales étant donné que j'ai vu que ça pouvait poser des problèmes sinon.
La compilation se passe bien, mais mon programme se prend un SIGSEGV lors du deuxième pthread_create.
Ma trace gdb :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
(gdb) r
Starting program: *****
[Thread debugging using libthread_db enabled]
[New Thread -151083328 (LWP 30561)]
 
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -151083328 (LWP 30561)]
0x0808063b in _dl_allocate_tls ()
(gdb) where
#0  0x0808063b in _dl_allocate_tls ()
#1  0x0060578e in pthread_create@@GLIBC_2.1 () from /lib/tls/libpthread.so.0
(après quelques "up" on se rend compte que c'est le deuxième pthread_create qui a provoqué le segfault)
Quelqu'un aurait-il une idée de la raison de ce problème?

Merci beaucoup d'avance