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
|
LDFLAGS += -fsanitize=undefined
|
||||||
|
|
||||||
# décommenté TD1 - partie V
|
# décommenté TD1 - partie V
|
||||||
#CFLAGS += -fsanitize=address
|
CFLAGS += -fsanitize=address
|
||||||
#LDFLAGS += -fsanitize=address -lpthread
|
LDFLAGS += -fsanitize=address -lpthread
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(NACHOS_SYS),MAC_OS_SYS)
|
ifeq ($(NACHOS_SYS),MAC_OS_SYS)
|
||||||
|
|
|
@ -128,6 +128,11 @@ AddrSpace::AddrSpace (OpenFile * executable)
|
||||||
|
|
||||||
pageTable[0].valid = FALSE; // Catch NULL dereference
|
pageTable[0].valid = FALSE; // Catch NULL dereference
|
||||||
|
|
||||||
|
#ifdef CHANGED
|
||||||
|
DEBUG('x', "Initialise thread counter\n");
|
||||||
|
Threads = 1;
|
||||||
|
#endif //CHANGED
|
||||||
|
|
||||||
AddrSpaceList.Append(this);
|
AddrSpaceList.Append(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@ class AddrSpace:public dontcopythis
|
||||||
// Dump program layout as SVG
|
// Dump program layout as SVG
|
||||||
unsigned NumPages() { return numPages; }
|
unsigned NumPages() { return numPages; }
|
||||||
#ifdef CHANGED
|
#ifdef CHANGED
|
||||||
|
int Threads; // count number of threads into address space
|
||||||
int AllocateUserStack();
|
int AllocateUserStack();
|
||||||
#endif
|
#endif
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -34,6 +34,10 @@ static void StartUserThread( void * args ){
|
||||||
machine->WriteRegister(StackReg, stack_addr);
|
machine->WriteRegister(StackReg, stack_addr);
|
||||||
DEBUG('x',"StackRegister: 0x%x\n", 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
|
// run our thread
|
||||||
machine->Run();
|
machine->Run();
|
||||||
}
|
}
|
||||||
|
@ -49,6 +53,11 @@ int do_ThreadCreate(int f, int arg){
|
||||||
|
|
||||||
// create a new Thread and start it
|
// create a new Thread and start it
|
||||||
Thread * newThread = new Thread("new thread");
|
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->space = currentThread->space;
|
||||||
newThread->Start(StartUserThread, args);
|
newThread->Start(StartUserThread, args);
|
||||||
|
|
||||||
|
@ -58,7 +67,9 @@ int do_ThreadCreate(int f, int arg){
|
||||||
void do_ThreadExit(){
|
void do_ThreadExit(){
|
||||||
DEBUG('x', "Enter do_ThreadExit function\n");
|
DEBUG('x', "Enter do_ThreadExit function\n");
|
||||||
// TODO: what should we do with thread space?
|
// 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();
|
currentThread->Finish();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue