X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/0c3ff62e3e040105afc8f47a73e42283cd0f0451..8c077434920dc49c791c9ed5c3ad7cbbc8faec15:/examples/sthread/pthread-producer-consumer.c diff --git a/examples/sthread/pthread-producer-consumer.c b/examples/sthread/pthread-producer-consumer.c index 8073105582..fe3fe5d960 100644 --- a/examples/sthread/pthread-producer-consumer.c +++ b/examples/sthread/pthread-producer-consumer.c @@ -45,9 +45,10 @@ static void* consumer(void* id) for (int i = 0; i < AmountConsumed; i++) { sem_wait(&full); pthread_mutex_lock(&mutex); - int item = buffer[out]; - if (do_output) + if (do_output) { + int item = buffer[out]; fprintf(stderr, "Consumer %d: Remove Item %d from %d\n", *((int*)id), item, out); + } out = (out + 1) % BufferSize; pthread_mutex_unlock(&mutex); sem_post(&empty); @@ -57,7 +58,7 @@ static void* consumer(void* id) int main(int argc, char** argv) { - char opt; + int opt; while ((opt = getopt(argc, argv, "c:C:p:P:q")) != -1) { switch (opt) { case 'q': @@ -75,7 +76,7 @@ int main(int argc, char** argv) case 'P': ProducerCount = atoi(optarg); break; - case '?': + default: /* '?' */ printf("unknown option: %c\n", optopt); break; } @@ -87,7 +88,7 @@ int main(int argc, char** argv) sem_init(&empty, 0, BufferSize); sem_init(&full, 0, 0); - int* ids = malloc(sizeof(int) * ((ProducerCount + ConsumerCount))); + int* ids = malloc(sizeof(int) * (ProducerCount + ConsumerCount)); for (int i = 0; i < ProducerCount + ConsumerCount; i++) ids[i] = i + 1; // The identity of each thread (for debug messages)