Producer Consumer program using semaphores and pthreads

前端 未结 2 1272
太阳男子
太阳男子 2020-12-13 11:09

I have written a code for producer-consumer problem.But I am not getting the output.There is no compilation error,but warning in my program.I am confused.Trying very hard.Bu

2条回答
  •  暖寄归人
    2020-12-13 11:49

    There are still compiler warnings. The correct way to get the integer value from a void pointer is:

    index = *(int*)arg;
    

    And, also to pass an integer pointer, is below:

    pthread_create(&idC,NULL,Consumer,(void*)&index);
    

    I still have some doubts as to how the Consumer or the Producer thread will receive the passed integer value since that is an address of the index variable in the for loop in the main thread. As soon as index gets incremented, the Consumer or Producer thread is affected by this increment.

提交回复
热议问题