Bonjour,
j'essaye de me progresser un peu dans le développement c++ en utilisant les programations multi-threads. J'essaye de compiler ce programme pour tester les mutex sous linux mais ça marche pas (j'ai trouvé l'exemple sur un site):
L'erreur que je reçoit est la suivante:
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 #include <stdio.h> #include <stdlib.h> #include <pthread.h> void *functionC(); pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER; int counter = 0; main() { int rc1, rc2; pthread_t thread1, thread2; /* Create independent threads each of which will execute functionC */ if( (rc1=pthread_create( &thread1, NULL, &functionC, NULL)) ) { printf("Thread creation failed: %d\n", rc1); } if( (rc2=pthread_create( &thread2, NULL, &functionC, NULL)) ) { printf("Thread creation failed: %d\n", rc2); } /* Wait till threads are complete before main continues. Unless we */ /* wait we run the risk of executing an exit which will terminate */ /* the process and all threads before the threads have completed. */ pthread_join( thread1, NULL); pthread_join( thread2, NULL); exit(0); } void *functionC() { pthread_mutex_lock( &mutex1 ); counter++; printf("Counter value: %d\n",counter); pthread_mutex_unlock( &mutex1 ); }
Est ce que vous pouvez m'aider pour trouver la solution svp ?user@ubuntu:~/Bureau/Tests Threads/Exemple_threads_mutex$ g++ -lpthread exemple_threads_mutex_1.c
exemple_threads_mutex_1.c: In function ‘int main()’:
exemple_threads_mutex_1.c:16: error: invalid conversion from ‘void* (*)()’ to ‘void* (*)(void*)’
exemple_threads_mutex_1.c:16: error: initializing argument 3 of ‘int pthread_create(pthread_t*, const pthread_attr_t*, void* (*)(void*), void*)’
exemple_threads_mutex_1.c:21: error: invalid conversion from ‘void* (*)()’ to ‘void* (*)(void*)’
exemple_threads_mutex_1.c:21: error: initializing argument 3 of ‘int pthread_create(pthread_t*, const pthread_attr_t*, void* (*)(void*), void*)’
user@ubuntu:~/Bureau/Tests Threads/Exemple_threads_mutex$
Une autre question que je voulais poser: dans cet exemple, est ce que chaque thread tourne sur un coeur ?? ou bien c'est le Système d'exploitation qui décide ?
Ci c'est le cas, comment je peux forcer un thread à tourner sur un deuxième coeur?
Merci beaucoup
Partager