Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as C by Jean ( 15 years ago )
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <semaphore.h>
int main(int argc, char *argv[]){
int th_1;
int th_2;
pthread_t thread_1;
pthread_t thread_2;
sem_t res_ecran;
sem_init(&res;_ecran,0,1);
void *afficher_phrase1(void *arg){
sem_wait(&res;_ecran);
int i;
char *p;
p = (char *) arg;
for(i=0;i<35;i++){
printf(">>THREAD#1 : %c \n",p[i]);
}
sem_post(&res;_ecran);
pthread_exit(0);
}
void *afficher_phrase2(void *arg){
sem_wait(&res;_ecran);
int i;
char *p;
p = (char *) arg;
for(i=0;i<35;i++){
printf(">>THREAD#2 : %c \n",p[i]);
}
sem_post(&res;_ecran);
pthread_exit(0);
}
char phrase_1[]="Realisation de test sur les threads";
char phrase_2[]="Espere que cela va bien fonctionner";
printf(">>MAIN>>Creation thread #1.\n");
th_1=pthread_create(&thread;_1,NULL,afficher_phrase1,(void *) phrase_1);
printf(">>MAIN>>Creation thread #2.\n");
th_2=pthread_create(&thread;_2,NULL,afficher_phrase2,(void *) phrase_2);
if(th_1)
printf("Erreur creation thread#1.\n");
if(th_2)
printf("Erreur creation thread#2.\n");
return EXIT_SUCCESS;
}
Revise this Paste