Example #1
0
/*
 * This is the loop for the supervisor thread.  It waits for 100ms, then
 * simulates one interval of time.
 */
static void simulator_supervisor_thread(void)
{
    print_gantt_header();

    /* Loop, performing execution every 100ms.  At each execution, we will
       display a line in the Gantt chart and check for pending I/O requests */
    while (1)
    {
        pthread_mutex_lock(&simulator_mutex);

        /* Exit when all processes terminate */
        if (processes_terminated >= PROCESS_COUNT)
        {
            print_final_stats();
            exit(0);
        }

        print_gantt_line();
        simulate_cpus();
        simulate_io();
        simulate_creat();
        simulator_time++;
        pthread_mutex_unlock(&simulator_mutex);

        mt_safe_usleep(1);
    }
}
Example #2
0
/*
 * idle() is your idle process.  It is called by the simulator when the idle
 * process is scheduled.
 *
 * This function should block until a process is added to your ready queue.
 * It should then call schedule() to select the process to run on the CPU.
 */
extern void idle(unsigned int cpu_id)
{
    /* FIX ME */
    schedule(0);

    /*
     * REMOVE THE LINE BELOW AFTER IMPLEMENTING IDLE()
     *
     * idle() must block when the ready queue is empty, or else the CPU threads
     * will spin in a loop.  Until a ready queue is implemented, we'll put the
     * thread to sleep to keep it from consuming 100% of the CPU time.  Once
     * you implement a proper idle() function using a condition variable,
     * remove the call to mt_safe_usleep() below.
     */
    mt_safe_usleep(1000000);
}