This project is an implementation of Kernel Threads in xv6 Operating System.
It is built based on the guidelines of this repository.
Userland threading library is also added with one-to-one mapping and synchronization with ticket-locks.
Appropriate system calls added for the implementation of threads and modified current system calls.
1. Vrinda Ahuja
2. Mrunal Kotkar
int clone(void(*fcn)(void *, void *), void *stack, int flags, void *arg1, void *arg2);
- Clone system call to create a thread of a process and is called from wrapper function of userland threading library
- fcn - Function pointer which runs in the created thread.
- flags - Flags for the clone system call.
- stack - Child stack to pass the function(fcn) arguments.
- arg1 & arg2 - Arguments to function fcn.
int join(int threadId);
- Join system call to wait for execution of current thread and block the other threads and finally free thread resources after execution.
- threadId - thread Id of the executing thread.
int gettid();
- gettid system call to get the thread Id of currently executing thread
int tgkill(int tgid, int tid, int sig);
- tgkill system call to kill the thread from thread group with thread group id as tgid and thread id as tid.
- tgid - thread group id (parent id)
- tid - thread id to be killed
- sig - signal number to be sent
- Setting up tgid for the process.
- Setting some other fields added to proc structure for implementation of threads.
- Changing one condition in closing all file descriptors if it is a thread and CLONE_FILE flag is set.
- Adding condition for killing a parent process if it has child threads, kill all threads with tgkill.
Functions implemented for userland threading library are:
- thread_create - Malloc the stack for thread and then calls clone system call.
- thread_join - Free the stack for the thread and call join system call.
- tlock_acquire - Acquires a ticket lock
- tlock_release - Reelease the ticket lock
- tlock_init - Initialize the ticket lock
Added a testing code to test all the functionality of Kernel threads with different test cases.