T1: P(Y); R := R*2; V(Y); T2: P(Y); R := R*R; V(Y); T3: P(Y); R := R+3; V(Y);
Voici le programme que j'ai tapé pour réaliser ceci:
#include <stdio.h>
#include <pthread.h>
int r=0;
#define NB_THREADS 3
pthread_t callThd[NB_THREADS];
pthread_mutex_t y;
void *t1 (void *arg)
{
pthread_mutex_lock (&y);
r=r*2;
pthread_mutex_unlock (&y);
pthread_exit(NULL);
}
void *t2 (void *arg)
{
pthread_mutex_lock (&y);
r=r*r;
pthread_mutex_unlock (&y);
pthread_exit(NULL);
}
void *t3 (void *arg)
{
pthread_mutex_lock (&y);
r=r+3;
pthread_mutex_unlock (&y);
pthread_exit(NULL);
}
int main (void)
{
int status,t;
pthread_mutex_init(&y, 1);
pthread_attr_setdetachstate(NULL, PTHREAD_CREATE_JOINABLE);
for (t=0; t<NB_THREADS;t++)
{
switch (t)
{
case 0 :
printf("%d\n", r);
pthread_create(&callThd[t], NULL, t1, (void *)t);
printf("%d\n", r);
break;
case 1 :
printf("%d\n", r);
pthread_create(&callThd[t], NULL, t2, (void *)t);
printf("%d\n", r);
break;
case 2 :
printf("%d\n", r);
pthread_create(&callThd[t], NULL, t3, (void *)t);
printf("%d\n", r);
break;
}
}
for (t=0; t<NB_THREADS; t++)
{
pthread_join (callThd[t], (void **)&status);
}
pthread_mutex_destroy(&y);
pthread_exit(NULL);
}
Il m'indique un Warning à la ligne 39: passing arg 2 of 'pthread_mutex_init' makes pointer from integer without a cast.
Soit seulement un warning donc j'essaie de lancer le programme et ça m'indique Bus Error (core dumped)
Si quelqu'un pouvait y regarder attentivement, ça m'aiderait bcp, vous pouvez aussi me contacter via msn sur hermanrenaud@gmail.com
Merci pour votre aide.
