当前位置: 首页>>代码示例>>C++>>正文


C++ Operation::parameters方法代码示例

本文整理汇总了C++中Operation::parameters方法的典型用法代码示例。如果您正苦于以下问题:C++ Operation::parameters方法的具体用法?C++ Operation::parameters怎么用?C++ Operation::parameters使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Operation的用法示例。


在下文中一共展示了Operation::parameters方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: handleIO

void Simulator::handleIO( const Operation& operation, int pid )
{
    string startMsg = "I/O: process " + to_string(pid) + " starting ";
    string endMsg = "Interrupt: process " + to_string(pid) + " done with ";

    if( operation.parameters().description == "hard drive" )
    {
        string type = operation.parameters().id == 'I' ? "input" : "output";

        display( startMsg + "hard drive " + type );
        wait( operation.parameters().duration );
        display( startMsg + "hard drive " + type );
    }
    else if( operation.parameters().description == "keyboard" )
    {
        display( startMsg + "keyboard input" );
        wait( operation.parameters().duration );
        display( endMsg + "keyboard input" );
    }
    else if( operation.parameters().description == "printer" )
    {
        display( startMsg + "printer output" );
        wait( operation.parameters().duration );
        display( endMsg + "printer output" );
    }
    else if( operation.parameters().description == "monitor" )
    {
        display( startMsg + "monitor output" );
        wait( operation.parameters().duration );
        display( endMsg + "monitor output" );
    }

    interrupts_.push(pid);
}
开发者ID:matthewjberger,项目名称:cs446Berger,代码行数:34,代码来源:Simulator.cpp

示例2: executeProgram

void Simulator::executeProgram( Program *program )
{
    int pid = program->process_control_block().processID;
    Operation* operation = program->step();
    char operationType = operation->parameters().id;

    // Create thread lambda
    auto ThreadStart = [this, operation, pid]()
    {
        handleIO(*operation, pid);
    };

    program->run();

    // Start
    if( operationType == 'A' &&
            operation->parameters().description == "start")
    {
        display("OS: starting process " + to_string(pid));
        operation = program->step();
    }

    // I/O
    if( operationType == 'I' || operationType == 'O')
    {
        display("Process: " + to_string(pid) + ": starting I/O");
        thread IO_thread(ThreadStart);
        IO_thread.detach(); // async, do not block

        program->suspend();
        suspendedPrograms_[pid] = *program;
    }

    // Processing
    else if( operationType == 'P' )
    {
        display("Process " + to_string(pid) + ": processing action");
        int quantum = 0;
        while( !operation->completed() && interrupts_.empty() )
        {
            quantum++;

            operation = program->step();
            wait( operation->parameters().cycleTime );

            if( quantum == configurationData.quantum )
            {
                // Launch a quantum interrupt to stop execution of the program
                interrupts_.push(0);
                display("Interrupt: quantum expired");
            }
        }

        if( operation->completed() )
        {
            display("Process " + to_string(pid) + ": end processing action");
        }
    }

    // The last operation in a program is an exit operation
    if( program->operations_left() <= 1 &&
            program->process_control_block().state != SUSPENDED)
    {
        program->exit();
        display("OS: removing process " + to_string(pid));
    }
}
开发者ID:matthewjberger,项目名称:cs446Berger,代码行数:67,代码来源:Simulator.cpp


注:本文中的Operation::parameters方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。