The sample code provided includes:
Test cases added
- test_one_thread.c: Tests the creation, execution, and cleanup of a single thread
- test_custom_schedule.c: Tests the scheduling of a few threads
- test_early_exit.c: Tests the handling of main thread exiting early
- test_many_threads.c: Tests the handling of the maximum allowed number of threads
- test_random_threads.c: Tests the handling of a few threads counting up to a random number
- test_new_threads.c: Tests the cleanup of old threads and the creation of new threads
- test_zombie_threads.c: Tests the handling of zombie threads (threads that have exited but have not been joined)
- test_wait_thread.c: Tests waiting for one busy thread to finish
typedef struct thread_control_block {
int id;
jmp_buf registers;
void *stack;
enum thread_status status;
void *ret_val;
} TCB;
void scheduler_init()
: Initializes the scheduler by assigning the first thread as the main threadvoid init_handler()
: Initializes the signal handler (schedule) for the timerTCB *get_new_thread()
: Returns a new thread from the thread poolvoid thread_init(TCB *new_thread)
: Allocates the stack for the new threadvoid reg_init(TCB *new_thread, void *(*start_routine)(void *), void *arg)
: Initializes the registers for the new thread to run the start routine