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
|
int Treatment(char *as_TreatmentDat, int nbThreads)
{
long ll_CountDeleteClientRatingDetail = 0,
ll_CountRatingScore = 0;
int li_rc = 0, i = 0, status = 0;
pthread_t callThread[nbThreads];
/* Initialisation du mutex */
pthread_mutex_init(&thdData.mutex, NULL);
/* On compte le nombre de lignes dans rating_score */
ll_CountRatingScore = 893564;
/* Avec ca, on compte le nombre de ligne à traiter par thread */
thdData.nbrOfRowToDo = ll_CountRatingScore / nbThreads;
/* Création des threads en leur disant leur "nom" afin qu'ils puissent savoir quelles lignes traiter. */
for(i = 0; i < nbThreads; i++)
{
pthread_create(&callThread[i], NULL, treatmentThread, &i);
}
/* Attende de la fin des threads */
for(i = 0; i < nbThreads; i++)
{
pthread_join(callThread[i], (void **)&status);
}
/* Destruction du mutex */
pthread_mutex_destroy(&thdData.mutex);
return li_rc;
}
/* Fonction executée par les threads */
void *treatmentThread(void *arg)
{
int li_rc = 0;
int threadCounter = 0;
int thdNum = *(int *)arg;
/* On calcule la fourchettes de lignes à traiter grâce au numéro du thread */
long start = 1 + (thdData.nbrOfRowToDo * thdNum);
long end = thdData.nbrOfRowToDo * (thdNum + 1);
printf("ceci est i : %d\n", &arg);
printf("Ich bin da thread n°%d et j'ai fait %ld rows!\n",thdNum, threadCounter);
printf("Mein start was %ld and mein endish was %ld\n", start, end);
pthread_exit((void*) 0);
} |