1 / 14

Threads

Threads. An Introduction to Multithreaded Programming. Bryce Tompkins, tompkins_bryce@emc.com. First There Was The Process . (from Wikipedia) a process is a running instance of a program, including all variables and other state.

vanig
Download Presentation

Threads

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.

E N D

Presentation Transcript


  1. Threads An Introduction to Multithreaded Programming Bryce Tompkins, tompkins_bryce@emc.com

  2. First There Was The Process • (from Wikipedia) a process is a running instance of a program, including all variables and other state. • The “state” includes open file descriptors/handles, address space, context (registers), etc. • UNIX and (modern) Windows processes exhibit similar characteristics. • Processes are scheduled preemptively by the kernel. Only one process can execute at a time on a single-processor/core computer. Multiple processes can execute simultaneously on multi-processor/core computers.

  3. Process Scheduling • UNIX and Windows are examples of Multitasking operating systems in which the OS is responsible for scheduling CPU time for each running process. • Multitasking gives the illusion of concurrency on a single processor machine. • The CPU-time allocated to a process and the frequency in which it is scheduled to run, are dependent on several factors: scheduling priority, policy (round-robin, FIFO), I/O. • A Context Switch occurs each time the kernel swaps one process for another off the CPU.

  4. The Context Switch • The kernel maintains the context of the process in registers on the CPU. The context includes: the Stack Pointer, the Program Counter, the Status Register and General Purpose Registers. • The context is stored in kernel memory and is retrieved and loaded at the process’s next scheduling. • The Context Switch allows the execution of the process to pick up where it left off when it is scheduled next.

  5. Memory Swapping • Virtual memory allows operating systems to map an address space much greater than the physical memory available. • Memory segments are “swapped” in and out of physical memory, to and from disk (swap space), on demand. Memory segments not used in a while are swapped out in favor of segments in demand.

  6. Then There Were Threads • (from Wikipedia) A thread is short for a thread of execution or a sequence of instructions. • Every process has at least one thread of execution. A process with more than one thread is referred to as a multithreaded process.

  7. Thread Characteristics • Threads are scheduled by the kernel. • Each thread maintains its own stack. • All threads within a process share the same address space and file descriptors/handles.

  8. Thread Benefits • A shared address space has benefits: • Shorter context switches since process memory is less likely to be swapped out. • Inter-thread communication is less cumbersome than inter-process communication • Asynchronous programming. Computation bound threads can run while I/O bound threads are blocking. • Multiple threads can run on multiple processors/cores.

  9. The Difficultly with Multithreaded Programming • A shared address space requires programmers to synchronize access to global and heap allocated data to prevent “race conditions”. A race condition occurs when two or more threads are in contention for a shared resource. • A race condition can cause corruption of data resulting in unexpected results or segmentation violations. • Synchronization methods may lead to deadlocks between multiple threads. • A delinquent thread can bring down (crash) the entire process.

  10. Threads in NetWorker 7.3 • Authentication requests in nsrexecd. • Message passing in NMC/gstd. • The Legato Portmapper in nsrexecd. • Concurrent recovers in nsrmmd.

  11. Thread Aware Tools • Solaris • ps –efL, GNU top, prstat, gdb • Windows • Task Manager • Mac OS X • Activity Monitor

  12. Demo

  13. Q & A

More Related