TD2 II.2 Finish thread Gracefuly

This commit is contained in:
Yorick Barbanneau 2021-11-16 22:40:34 +01:00
parent 615d121a76
commit feff887fa0
2 changed files with 8 additions and 3 deletions

View file

@ -131,8 +131,8 @@ ExceptionHandler (ExceptionType which)
#ifdef CHANGED
case SC_Exit:
{
while (1)
currentThread->Yield();
// while (1)
// currentThread->Yield();
int ret = machine->ReadRegister(4);
printf("Exit code %d\n", ret);
interrupt->Powerdown();

View file

@ -68,8 +68,13 @@ void do_ThreadExit(){
DEBUG('x', "Enter do_ThreadExit function\n");
// TODO: what should we do with thread space?
// Probalely desallocate it... if no threads remain
currentThread->space->Threads--;
// currentThread->space->Threads--;
DEBUG('x', "Decrease numbers of Threads:%d\n",currentThread->space->Threads);
if ( --currentThread->space->Threads == 0){
// No threads remains, desallocate addrspace
delete currentThread->space;
interrupt->Powerdown();
}
currentThread->Finish();
}
#endif