1
I am studying Operating System and I have an exercise to do in C++ and I am with dual (the book brings only in Java), I have to implement a classic problem of reader and writer using semaphores and control variables... And I’m studying some codes. The function below was written in C, but I want to write it in C++.
What an equivalent of that would look like? void *reader(void *i)
. I’ve never seen a structure like this in C++, a pointer of void
which has as parameter a pointer void
again or something.
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);
}
I solved the problem already, I forgot to mark there as solved, in vdd the code follows the right logic for the solution of the problem... this missing only solve the starvation problem for the algorithm I did. from now on thank.
– Anderson Augusto