Je veux être fait pour 10 fois, pour numériser le numéro et l'imprimer à nouveau. Comment puis je faire ça?problème avec les threads
#include <stdio.h>
#include <pthread.h>
#include <semaphore.h>
sem_t m;
int n;
void *readnumber(void *arg)
{
scanf("%d",&n);
sem_post(&m);
}
void *writenumber(void *arg)
{
//int x =3;
//while(x>0)
//{
//x = x-1;
sem_wait(&m);
printf("%d",n);
//}
}
int main(){
pthread_t t1, t2;
sem_init(&m, 0, 0);
pthread_create(&t2, NULL, writenumber, NULL);
pthread_create(&t1, NULL, readnumber, NULL);
pthread_join(t2, NULL);
pthread_join(t1, NULL);
sem_destroy(&m);
return 0;
}
Je ne suis pas sûr que cette situation soit vraiment urgente pour justifier plusieurs points d'exclamation. – Syntactic
Vous avez besoin d'une balise 'homework'? –
double post: http://stackoverflow.com/questions/2764696/c-threads-question – KillianDS