TWiki> CS385fall14 Web>Homework6 (revision 4)EditAttach

adding threading support to xv6

In this homework, we make some major changes to xv6 to add support for kernel threads to the OS. A single process may execute multiple kernel threads, which may operate concurrently on a multi-core machine.

The hw6 template already includes some significant refactoring. The main changes are the replacement of the "proc" global with a "current" global, which holds the current thread. Also, the ptable is an array of struct thread instead of struct proc, where each struct thread has a pointer to a potentially shared struct proc.

However, in the template there is a one-to-one mapping between threads and processes. Your job is to make that a many-to-one mapping by adding thread management facilities and enforcing correct thread semantics on existing system calls.

Basic Thread creation

With fork(), a process is copied wholesale. A skeleton exists for the system call sys_clone(). Complete the implementation, to make each of the thread test cases (programs thread1..threadN) work correctly.

As is usually the case, it'll be easier if you do things a step at a time. For thread creation, I would suggest:

  1. make thread1 print hello world, by a little bit of code in clone that sacrifices the original thread
  2. make thread1 print both hello world and hello from main, by forking off a new thread
  3. make thread2 print a bunch of numbers by setting up shared memory

Thread exit

You'll find that the third test case, thread3 crashes at the end of its run. When the created thread has finished running f() it tries to return to the calling function, but it doesn't exist.

  • make thread3 not crash by adding a system call thread_exit (to test, temporarily add a call to thread_exit at end of f)
  • update thread_create in ulib.c to have created threads automatically call thread_exit when their initial function returns

join(): waiting for threads to finish

exec() and exit() semantics

Edit | Attach | Print version | History: r8 | r6 < r5 < r4 < r3 | Backlinks | Raw View | Raw edit | More topic actions...
Topic revision: r4 - 2014-10-09 - 17:55:53 - Main.jakob
 
Copyright 2016 The Board of Trustees
of the University of Illinois.webmaster@cs.uic.edu
WISEST
Helping Women Faculty Advance
Funded by NSF