1 / 14


THREADS. CSC 8320 Advanced Operating Systems Neelima Jullapelli. Contents. Introduction to threads Characteristics of Threads Advantages of Threads User Threads Kernel Threads Threads in distributed environment Programming with Threads RPCS and Threads. Two types of processes.

Download Presentation


An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.


Presentation Transcript

  1. THREADS CSC 8320 Advanced Operating Systems Neelima Jullapelli

  2. Contents • Introduction to threads • Characteristics of Threads • Advantages of Threads • User Threads • Kernel Threads • Threads in distributed environment • Programming with Threads • RPCS and Threads

  3. Two types of processes • “Heavyweight” process normal process that does not share memory with other processes • “Lightweight” process: Threads memory is shared with other processes maintains own state ,program counter, stack • A Thread is dispatchable unit of work executes sequentially and is interruptable. • A process is collection of one or more threads.

  4. Thread • Characteristics All threads have exactly the same address space - Therefore has access to same global variables - can also wipe out other thread’s work(overwrite variables,etc) - All threads share the same set of open files, child processes, timers , and signals ,semaphores, ports etc. - Threads can be in any one of several states: ready, running, blocked or terminated

  5. Advantages of Threads • Sharing data is easy -reduction in interprocess communication overhead -just synchronize critical sections in shared data • If the server had multiple threads of control, a second thread could run while the first one was sleeping the net result would be higher throughput and better performance. • Ease of programming -only one address space to worry about

  6. User Threads • Thread package runs on top of kernel - referred to as ‘user-space runtime system’ - kernel maintains processes -user program maintains threads the runtime system • Blocking system calls -if a blocking system call goes to kernel the kernel suspends the process -wants to call another thread when one becomes blocked use non-blocking calls (some OS’s don't support these) Unix select()- use instead of read –if read() would block, call thread manager instead

  7. User threads (contd…) • Preemption of processes - no good way to perform preemptive scheduling clock interrupts are at process level -thread must voluntarily give up CPU -can lead to deadlock for example waiting for a semaphore with a blocking system call. • Advantages - can run threads on process-oriented systems(like unix) -each process can have customised scheduling algorithm -context switch is minimized

  8. Kernel Threads • Kernel schedules threads not processes -when a thread blocks,kernel can schedule: another thread from the same process A thread from different process -context switch is more expensive kernel has to maintain process tables with thread entries • user-level problems with page faults, deadlock don’t occur

  9. Threads in distributed Environment • Multiprocessors -task environment located in shared memory -threads can run in parallel on different CPU’S -just need to synchronize shared memory access • Threads for the client/server model -each client makes a request to the server -server executes identical procedure for all calls -threads reduce overhead -make server program easier

  10. Programming with threads • Thread management -static threads: number of threads fixed -dynamic threads: threads can be created and destroyed at runtime. • Mutex -essentially a binary semaphore. -in C threads package: a)mutex_lock(mutexId) b)mutex_unlock(mutexId) -deadloack can occur with semaphore locks.

  11. Cont….. • Condition variables (CV) -use for long term waiting -using signals on CV reduces probablity of deadlock. -condition_wait(conditionId, mutexId) a) queue request on conditionId b) then mutex is released. -condition_signal(conditionId) a)if a thread is queued in conditionId, unlock it.

  12. RPC’S and threads • Use shared memory to pass parameters,results -when started kernel given interfaces for both client and server. -kernel creates an argument stack shared by both -when client calls server client puts info into stack,trap to kernel. Server reads directly from it address spaceand the results are passed in the same manner • Pop-up threads the thread that is created spontaneously to handle an incoming RPC is occasionally referred to as pop-up thread

  13. Current research • Dynamic thread resizing for speculative multithreaded processorsZahran, M.; Franklin, M.;Computer Design, 2003. Proceedings. 21st International Conference • Dynamically Controlled Resource Allocation in SMT ProcessorsCazorla, F.J.; Ramirez, A.; Valero, M.; Fernandez, E.;Microarchitecture, 2004. MICRO-37 2004. 37th International Symposium on04-08 Dec. 2004 Page(s):171 - 182

  14. References: • Distributed operating systems by Andrew s Tanenbaum • Operating system concepts by silberscatz Galvin • http://ieeexplorer.ieee.org

More Related