Os project in C language
Budget: $30 – $250 USD
1 Overview
A thread library provides an API for creating and managing threads. Support for threads is provided either at user-level or by the kernel, depending on the goals of the end-product. Kernel level threads are managed directly by the operating system, where each thread is viewed as an independent task, managed via system calls from user space, scheduled by the kernel, and good for applications that frequently block. User level threads, on the other hand, are managed without kernel support, are defined by the user level thread library, can be used on systems that have no kernel-level thread support, thread switching is as efficient as function calls, but the kernel knows nothing about them so any blocking affects all threads.
2 Assignment
You will implement a simplified version of many-to-one user level threads in the form of a library called Simple Threads.
In the many-to-one model for user level threads, all threads execute on the same kernel thread. As there is only one kernel-level thread associated with the process (the process containing threads is represented by a single context within the kernel), only one user-level thread may run at a time.
Your thread manager will include a preemptive round-robin scheduler. If a thread does not yield during its time-slice, it will be preempted and one of the other ready threads will be resumed. The preempted and resumed threads should change state accordingly.
Important: You will NOT use pthreads anywhere in your implementation. The intent is to create similar functionality entirely in a user-space program.
You will also implement thread synchronization and demonstrate that it works as expected. Imple-
ment the equivalent of pthread mutex lock, pthread mutex unlock, and pthread join, and pthread barrier wait – call them uthread mutex lock, uthread mutex unlock, uthread join, and uthread barrier wait –
in your user threads (additional functions may be needed to complete these components; use your
best judgement). You may use semaphores from semaphore.h, but you may NOT use the pthread
library functions.
2.1 Preliminaries
To complete this assignment, there are two necessary concepts you must master: managing execution contexts and signal handlers. Examples are given for both for you to examine and reuse.
2.1.1 Execution Contexts
The example code that is the essential starting point for grasping execution context management is in the contexts.c source file. Read the source, pay close attention to the comments. To fully understand the code, play with it while reading the following manual pages (or ask ChatGPT for explanations and examples):
• getcontext
• setcontext
• makecontext • swapcontext
2.1.2 Timers
In timer.c you will find an example of how to set a timer. See chapter 10 of Advanced Programming in the UNIX Environment for an authoritative treatment of signals.
In order to implement preemptive scheduling, you will need to set a timer, and register a timer handler that will act as the thread scheduler for your library. You will figure out how to suspend the running thread and resume a thread from the ready queue.
A thread library provides an API for creating and managing threads. Support for threads is provided either at user-level or by the kernel, depending on the goals of the end-product. Kernel level threads are managed directly by the operating system, where each thread is viewed as an independent task, managed via system calls from user space, scheduled by the kernel, and good for applications that frequently block. User level threads, on the other hand, are managed without kernel support, are defined by the user level thread library, can be used on systems that have no kernel-level thread support, thread switching is as efficient as function calls, but the kernel knows nothing about them so any blocking affects all threads.
2 Assignment
You will implement a simplified version of many-to-one user level threads in the form of a library called Simple Threads.
In the many-to-one model for user level threads, all threads execute on the same kernel thread. As there is only one kernel-level thread associated with the process (the process containing threads is represented by a single context within the kernel), only one user-level thread may run at a time.
Your thread manager will include a preemptive round-robin scheduler. If a thread does not yield during its time-slice, it will be preempted and one of the other ready threads will be resumed. The preempted and resumed threads should change state accordingly.
Important: You will NOT use pthreads anywhere in your implementation. The intent is to create similar functionality entirely in a user-space program.
You will also implement thread synchronization and demonstrate that it works as expected. Imple-
ment the equivalent of pthread mutex lock, pthread mutex unlock, and pthread join, and pthread barrier wait – call them uthread mutex lock, uthread mutex unlock, uthread join, and uthread barrier wait –
in your user threads (additional functions may be needed to complete these components; use your
best judgement). You may use semaphores from semaphore.h, but you may NOT use the pthread
library functions.
2.1 Preliminaries
To complete this assignment, there are two necessary concepts you must master: managing execution contexts and signal handlers. Examples are given for both for you to examine and reuse.
2.1.1 Execution Contexts
The example code that is the essential starting point for grasping execution context management is in the contexts.c source file. Read the source, pay close attention to the comments. To fully understand the code, play with it while reading the following manual pages (or ask ChatGPT for explanations and examples):
• getcontext
• setcontext
• makecontext • swapcontext
2.1.2 Timers
In timer.c you will find an example of how to set a timer. See chapter 10 of Advanced Programming in the UNIX Environment for an authoritative treatment of signals.
In order to implement preemptive scheduling, you will need to set a timer, and register a timer handler that will act as the thread scheduler for your library. You will figure out how to suspend the running thread and resume a thread from the ready queue.
Related categories:
C Programming
C# Programming
Software Architecture
C++ Programming
x86/x64 Assembler