Fill This Form To Receive Instant Help

Help in Homework
trustpilot ratings
google ratings


Homework answers / question archive / CS514 Spring ’23 - User Level Threads 1 Overview A thread library provides an API for creating and managing threads

CS514 Spring ’23 - User Level Threads 1 Overview A thread library provides an API for creating and managing threads

Computer Science

CS514 Spring ’23 - User Level Threads
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. (Credit for the example code and some of the assignment parameters goes
to the Operating Systems Course from Uppsala University∗.)
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. Implement
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.
∗http://www.it.uu.se/education/course/homepage/os/vt18/module-4/simple-threads/
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.
3 Grading
Hard requirements (no points without these):
• Assignment is to be done in C, without the use of pthreads, and is to compile and run on
os.cs.siue.edu.
• You will also devise a solution using YOUR threads that shows that all your functions work.
I suggest implementing dining philosophers, which should sufficiently exercise your code. In
your design file, describe what you did and how it convinces you that your solution works.
• Place all of your thread code in uthreads.h and uthreads.c. Your synchronization example
(see the previous point), thread initialization, etc, should be in a file called solution.c. Use a
makefile to compile these three files into a executable program.
• If you use ChatGPT to produce examples and synthesize parts of the code, you must include
a transcript in your design file.
• 10 points if there is a reasonable attempt at a solution conforming to the original problem
statement.
• 10 points if a single thread is initialized and runs
• 10 points if more than one thread successfully runs by yielding
• 20 points if many threads are being scheduled preemptively, the round-robin scheduler works
to select each thread in turn, and all threads run to completion.
• 15 points for uthread mutex lock.
• 15 points for uthread mutex unlock.
• 15 points for uthread barrier wait.
• 5 points for uthread join.
4 What to Turn In
A .tgz of your solution files. Design and usage notes should be included in a design.txt, also to be
turned in via the .tgz archive. Design.txt should clearly state how and what you’ve done to convince
yourself that your code works. Include a Makefile that builds your solution on os.cs.siue.edu. Use
of ChatGPT is not required, but if used, include a transcript of the entire chat (include all prompts
and responses) in your design.txt

Option 1

Low Cost Option
Download this past answer in few clicks

18.99 USD

PURCHASE SOLUTION

Already member?


Option 2

Custom new solution created by our subject matter experts

GET A QUOTE