TD2 II.4 Call exit if there is no space avaible on Stack

Put Thread in sleep mode was a bad idea beause of synch (barrier for example)
This commit is contained in:
Yorick Barbanneau 2021-11-19 14:12:49 +01:00
parent 4da093ca38
commit 3877e32b59
3 changed files with 22 additions and 10 deletions

View file

@ -15,7 +15,6 @@ static void StartUserThread( void * args ){
// because we only have a void in our function definition
ThreadArgs_t * cpy_args;
cpy_args = (ThreadArgs_t *) args;
int stack_addr = currentThread->space->AllocateUserStack();
// init register
for (int i = 0; i < NumTotalRegs; i++ ) {
@ -32,8 +31,8 @@ static void StartUserThread( void * args ){
DEBUG('x',"Register 4: 0x%x\n", cpy_args->arg);
// init stack
machine->WriteRegister(StackReg, stack_addr);
DEBUG('x',"StackRegister: 0x%x\n", stack_addr);
machine->WriteRegister(StackReg, cpy_args->stackAddr);
DEBUG('x',"StackRegister: 0x%x\n", cpy_args->stackAddr);
// All our registers have values, we can desallocate our cpy_args
free(cpy_args);
@ -51,7 +50,13 @@ int do_ThreadCreate(int f, int arg){
ThreadArgs_t * args = (ThreadArgs_t *) malloc(sizeof(ThreadArgs_t));
args->f = f;
args->arg = arg;
// Check if we can allocate Stack for our son
int stackAddr = currentThread->space->AllocateUserStack();
if ( stackAddr == -1 ) {
fprintf(stderr, "Segmentation Fault - no space avaible on stack\n");
Exit(1);
}
// create a new Thread and start it
Thread * newThread = new Thread("new thread");