TD2 I.6+ Implement thread counter
This commit is contained in:
parent
1a97a8aef5
commit
615d121a76
4 changed files with 26 additions and 9 deletions
|
@ -41,8 +41,8 @@ CFLAGS += -fsanitize=undefined
|
|||
LDFLAGS += -fsanitize=undefined
|
||||
|
||||
# décommenté TD1 - partie V
|
||||
#CFLAGS += -fsanitize=address
|
||||
#LDFLAGS += -fsanitize=address -lpthread
|
||||
CFLAGS += -fsanitize=address
|
||||
LDFLAGS += -fsanitize=address -lpthread
|
||||
endif
|
||||
|
||||
ifeq ($(NACHOS_SYS),MAC_OS_SYS)
|
||||
|
|
|
@ -128,6 +128,11 @@ AddrSpace::AddrSpace (OpenFile * executable)
|
|||
|
||||
pageTable[0].valid = FALSE; // Catch NULL dereference
|
||||
|
||||
#ifdef CHANGED
|
||||
DEBUG('x', "Initialise thread counter\n");
|
||||
Threads = 1;
|
||||
#endif //CHANGED
|
||||
|
||||
AddrSpaceList.Append(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@ class AddrSpace:public dontcopythis
|
|||
// Dump program layout as SVG
|
||||
unsigned NumPages() { return numPages; }
|
||||
#ifdef CHANGED
|
||||
int Threads; // count number of threads into address space
|
||||
int AllocateUserStack();
|
||||
#endif
|
||||
private:
|
||||
|
|
|
@ -34,6 +34,10 @@ static void StartUserThread( void * args ){
|
|||
machine->WriteRegister(StackReg, stack_addr);
|
||||
DEBUG('x',"StackRegister: 0x%x\n", stack_addr);
|
||||
|
||||
// All our registers have values, we can desallocate our cpy_args
|
||||
free(cpy_args);
|
||||
cpy_args = NULL;
|
||||
|
||||
// run our thread
|
||||
machine->Run();
|
||||
}
|
||||
|
@ -49,6 +53,11 @@ int do_ThreadCreate(int f, int arg){
|
|||
|
||||
// create a new Thread and start it
|
||||
Thread * newThread = new Thread("new thread");
|
||||
|
||||
// increment number of threads
|
||||
currentThread->space->Threads++;
|
||||
DEBUG('x', "Increase numbers of Threads:%d\n",currentThread->space->Threads);
|
||||
|
||||
newThread->space = currentThread->space;
|
||||
newThread->Start(StartUserThread, args);
|
||||
|
||||
|
@ -58,7 +67,9 @@ int do_ThreadCreate(int f, int arg){
|
|||
void do_ThreadExit(){
|
||||
DEBUG('x', "Enter do_ThreadExit function\n");
|
||||
// TODO: what should we do with thread space?
|
||||
// Probalely desallocate it...
|
||||
// Probalely desallocate it... if no threads remain
|
||||
currentThread->space->Threads--;
|
||||
DEBUG('x', "Decrease numbers of Threads:%d\n",currentThread->space->Threads);
|
||||
currentThread->Finish();
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue