0

os-sim.h

typedef enum {
    PROCESS_NEW = 0,
    PROCESS_READY,
    PROCESS_RUNNING,
    PROCESS_WAITING,
    PROCESS_TERMINATED
} process_state_t;

typedef struct _pcb_t {
    const unsigned int pid;
    const char *name;
    const unsigned int static_priority;
    process_state_t state;               <<---Trying to access this
    op_t *pc;
    struct _pcb_t *next;
} pcb_t;

file1.c

static pcb_t **current;

extern void yield(unsigned int cpu_id)
{
    /* FIX ME */
    while (1)
    {
    pthread_mutex_lock(&current_mutex);
    current[cpu_id].state = PROCESS_WAITING;  ///<-------ERROR HERE
    pthread_mutex_unlock(&current_mutex);
    break;
    }
    schedule(cpu_id);
}

in main method():  
current = malloc(sizeof(pcb_t*) * 10);

I have error in this line current[cpu_id].state = PROCESS_WAITING;

error: request for member ‘state’ in something not a structure or union

What does this error mean?
Is this not the right way to access current array which holds pcb_t?
If so, how do i access the current array? and state field?

1 Answer 1

5

You're likely looking for:

current[cpu_id]->state = PROCESS_WAITING;

The type of current is pcb_t **. So the type of current[cpu_id] is pcb_t *.

Sign up to request clarification or add additional context in comments.

3 Comments

so you use -> when it's ** and you use . when it's *?
@sharth Wait, if he allocated memory for only 10 pointers malloc(sizeof(pcb_t*) * 10) then how does that work? He can't store anything in state as space hasn't been allocated(?)
@Armin: That's a good point. I'd be happy to see you expand on that point in either a separate answer, as an edit to mine, or in these comments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.