"void * reader (void * i)" What is the equivalent in C ++?

1

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);
}
    
asked by anonymous 08.12.2017 / 21:46

1 answer

0

Virtually all C code is a C ++ code, so this is in C ++.

It's not a idiomatic code. In C ++ I would probably use a template instead of a void * , I'd use a stream instead of printf() , it is possible that other things would be done differently depending on the context, but the code is still C ++.

This code seems to have several errors, there is another problem.

    
11.12.2017 / 14:37