diff --git a/code/userprog/exception.cc b/code/userprog/exception.cc index df7ca0e..c8c0a83 100644 --- a/code/userprog/exception.cc +++ b/code/userprog/exception.cc @@ -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(); diff --git a/code/userprog/userthread.cc b/code/userprog/userthread.cc index 014d574..da97ea0 100644 --- a/code/userprog/userthread.cc +++ b/code/userprog/userthread.cc @@ -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