0

操作系统-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;

文件1.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);

我在这一行有错误current[cpu_id].state = PROCESS_WAITING;

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

这个错误是什么意思?
这不是访问包含 pcb_t 的当前数组的正确方法吗?
如果是这样,我如何访问当前数组?和状态字段?

4

1 回答 1

5

您可能正在寻找:

current[cpu_id]->state = PROCESS_WAITING;

的类型currentpcb_t **。所以 的类型current[cpu_id]pcb_t *

于 2013-04-01T22:01:58.263 回答