示例#1
0
文件: Process.cpp 项目: HENRDS/APGer2
/**
 * Processos serão finalizados quando for invocada a chamada static void Process::exit(int status = 0), que precisa ser
 * implementada. A implementação dessa chamada deve desalocar a memória do processo invocando
 * void MemoryManager::deallocateMemory(Partition* partition), excluir todas as threads desse processo, excluir o processo (destruir
 * o objeto Process), invocar o escalonador para escolher outra thread, invocando Thread* Scheduler::choose() e então
 * o despachador para iniciar a execução da thread escolhida pelo escalonador, invocando
 * void Dispatcher::dispatch(Thread* previous, Thread* next).
 **/
void Process::exit(int status) { /*static*/
    Debug::cout(Debug::Level::trace, "Process::exit(" + std::to_string(status) + ")");
    
    if (Thread::running() != nullptr) {
        Process* proc = Thread::running()->getProcess();
        System::memoryManager()->deallocateMemory(proc->_memInfo._partition);
        Process::getProcessesList()->remove(proc);
        // Segmentation fault is a bitch...
        HQueue<Thread*>* threads = new HQueue<Thread*>();
        // criar lista e adicionar elas na lista depois excluir
        for (std::list<Thread*>::iterator it = Thread::getThreadsList()->begin(); it != Thread::getThreadsList()->end(); it++) {
            if ((*it)->getProcess() ==  proc) 
                threads->push((*it));
        }
         
        while (!threads->empty()) {
            Thread *t = threads->pop();
            if (t->_state == Thread::State::READY)
                System::scheduler()->remove(t);
            delete t;
        }
        delete threads;
        delete proc;
    }
    Thread::chooseAndDispatch();
}
示例#2
0
TEST(queue, proverka_popa)
{
	HQueue<int> *a = new HQueue<int> (2);
	a->push(5);
	a->pop();
	EXPECT_EQ(a->isEmpty(), 1);
}
示例#3
0
TEST(queue, throw_if_pop_iz_pustoi_queue)
{
	HQueue<int> *a = new HQueue<int> (2);
	ASSERT_ANY_THROW(a->pop());
}