I'm studying Operating System and I have an exercise to do in C ++ and I'm having doubts (the book only comes in Java), I have to implement a classic reader and writer problem using traffic lights and control variables ... And I'm studying some codes. The function below was written in C, but I want to write it in C ++.
How would something equivalent to this look? void *reader(void *i)
. I've never seen a structure similar to this in C ++, a pointer of void
that has a pointer void
as a parameter again or something like that.
void *reader(void *i)
{
printf("\n-------------------------");
printf("\n\n reader-%d is reading",i);
sem_wait(&z);
sem_wait(&rsem);
sem_wait(&x);
readcount++;
if(readcount==1)
sem_wait(&wsem);
sem_post(&x);
sem_post(&rsem);
sem_post(&z);
printf("\nupdated value : %d",sh_var);
sem_wait(&x);
readcount--;
if(readcount==0)
sem_post(&wsem);
sem_post(&x);
}