CS 350.docx - Operating System is responsible for making it easy to run programs at the same time share memory and enabling problem to interact with

CS 350.docx - Operating System is responsible for making it...

This preview shows page 1 - 3 out of 25 pages.

.
Image of page 1
Multi-Thread: has more than one point of execution o A thread can create new threads using thread_fork (New thread start execution in a function specified as a parameter to thread_fork ) o The original thread and the new thread created by thread_fork proceed concurrently o Context switch switches the process between 2 threads Decide which thread will run next Save register contents of current thread Load register contents of next thread Running thread calls thread_yield (voluntarily allows other thread to run) Running thread preempted (involuntarily stop running) Running thread calls thread_exit (terminate running thread) Running thread blocks, via a call to wchan_sleep o We save state to a process control block o We store the state of each thread to thread control block o Any stack allocated variables etc. are store in thread-local storage o All threads share access to the program’s global variables and heap o Each thread’s function activations are private to that thread Why we use thread? o Parallelism: the task of transforming the standard single-threaded program into a program that does this sort of work on multiple CPUs programs can run faster o Parallelism exposed by threads enables better processor utilization If one thread has to block, another may be able to run Refer to note: shared data (make sure understand the counter question) o Solve by synchronization Critical Section: a piece of code that access a shared resource, usually a variable or a data structure
Image of page 2
Image of page 3

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture