All pastes #75639 Raw Edit

Something

public text v1 · immutable
#75639 ·published 2006-06-30 11:39 UTC
rendered paste body
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/errno.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include </usr/include/semaphore.h>


#define NITER 10000000
sem_t mutex;

int count = 0;

void * ThreadAdd(void * a)
{
        int i, tmp;

        while(1){
                printf("this is in the thread %d",count);
                sem_wait(&mutex);
        }
}

int main(int argc, char * argv[])
{
        pthread_t tid1, tid2;
        sem_init(&mutex, 0, 1);
        int i=10;

        if(pthread_create(&tid1, NULL, ThreadAdd, NULL))
        {
                printf("\n ERROR creating thread 1");
                exit(1);
        }
        if(pthread_join(tid1, NULL))    /* wait for the thread 1 to finish */
        {
                printf("\n ERROR joining thread");
                exit(1);
        }

       /* here my intention is upto 10 elements loop has to go */

        while (i>10){
                printf("Enter the id please \n");
                scanf("%d",count);
                i = i-1;
                sem_post(&mutex);
        }


        pthread_exit(NULL);
}