diff --git a/src/multitasking/process.c b/src/multitasking/process.c index d2e76ac..ed873a0 100644 --- a/src/multitasking/process.c +++ b/src/multitasking/process.c @@ -46,13 +46,19 @@ struct pcb *create_process(uint8_t uid) return NULL; } memcpy(new_pcb->heap, current_pcb->heap, 4096); - new_pcb->next = current_pcb->next; - new_pcb->prev = current_pcb; - current_pcb->next = new_pcb; - if (current_pcb->prev == current_pcb) - current_pcb->prev = new_pcb; + if (current_pcb) { + new_pcb->next = current_pcb->next; + new_pcb->prev = current_pcb; + current_pcb->next = new_pcb; + if (current_pcb->prev == current_pcb) + current_pcb->prev = new_pcb; + } + else { + current_pcb = new_pcb; + } new_pcb->signals.pending = SIG_IGN; + new_pcb->thread_list = NULL; return new_pcb; } diff --git a/src/multitasking/thread.c b/src/multitasking/thread.c index 48b7dc9..717a50a 100644 --- a/src/multitasking/thread.c +++ b/src/multitasking/thread.c @@ -28,9 +28,14 @@ struct tcb *create_thread(struct pcb *process, void (*routine)(void)) new_tcb->state = NEW; struct tcb *it = process->thread_list; - while (it) - it = it->next; - it = new_tcb; + if (it) { + while (it) + it = it->next; + it = new_tcb; + } + else { + process->thread_list = new_tcb; + } return new_tcb; }