Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
Chapter 4:   Threads
What’s in a process? A process consists of (at least): an address space the code for the running program the data for the running program an execution stack and stack pointer (SP) traces state of procedure calls made the program counter (PC), indicating the next instruction a set of general-purpose processor registers and their values a set of OS resources open files, network connections, sound channels, …
Concurrency Imagine a web server, which might like to handle multiple requests concurrently While waiting for the credit card server to approve a purchase for one client, it could be retrieving the data requested by another client from disk, and assembling the response for a third client from cached information Imagine a web client (browser), which might like to initiate multiple requests concurrently The IT home page has 10 “src= …” html commands, each of which is going to involve a lot of sitting around!  Wouldn’t it be nice to be able to launch these requests concurrently? Imagine a parallel program running on a multiprocessor, which might like to employ “physical concurrency” For example, multiplying a large matrix – split the output matrix into k regions and compute the entries in each region concurrently using k processors
What’s needed? In each of these examples of concurrency (web server, web client, parallel program): Everybody wants to run the same code Everybody wants to access the same data Everybody has the same privileges (most of the time) Everybody uses the same resources (open files, network connections, etc.) But you’d like to have multiple hardware execution states: an execution stack and stack pointer (SP) traces state of procedure calls made the program counter (PC), indicating the next instruction a set of general-purpose processor registers and their values

Recommended for you

Thread management
Thread management Thread management
Thread management

The document discusses processes and threads. A process is an executing program with resources, while a thread is a sequence of execution within a process that shares its resources. Threads have lower overhead than processes and allow for multitasking. However, multithreaded programs are more difficult to debug. Thread management can be done at the user level or kernel level. Different models map user threads to kernel threads, such as many-to-one, one-to-one, and many-to-many.

Threads .ppt
Threads .pptThreads .ppt
Threads .ppt

This document discusses threads and multithreading in operating systems. A thread is a flow of execution through a process with its own program counter, registers, and stack. Multithreading allows multiple threads within a process to run concurrently on multiple processors. There are three relationship models between user threads and kernel threads: many-to-many, many-to-one, and one-to-one. User threads are managed in userspace while kernel threads are managed by the operating system kernel. Both have advantages and disadvantages related to performance, concurrency, and complexity.

Threads
ThreadsThreads
Threads

User-level threads (ULTs) are managed by a user-level threads library and do not require a kernel context switch when switching between threads. However, if one ULT blocks, the entire process is blocked. Kernel-level threads (KLTs) are managed by the kernel, allowing true parallelism within a process on multiprocessors. A mode switch is required to switch KLTs but blocking a single KLT does not block the entire process. Threads provide benefits over processes like lower overhead for creation, termination, and context switching.

How could we achieve this? Given the process abstraction as we know it: fork several processes cause each to  map  to the  same  physical memory to share data This is really inefficient!! space:  PCB, page tables, etc. time: creating OS structures, fork and copy address space, etc. So any support that the OS can give for doing multi-threaded programming is a win
Can we do better? Key idea: separate the concept of a  process  (address space, etc.) … from that of a minimal “ thread of control ” (execution state:  PC, etc.) This execution state is usually called a  thread , or sometimes, a  lightweight process
Single-Threaded Example Imagine the following C program: main() {   ComputePI(“pi.txt”);   PrintClassList(“clist.text”); } What is the behavior here? Program would never print out class list Why? ComputePI would never finish
Use of Threads Version of program with Threads: main() { CreateThread(ComputePI(“pi.txt”));   CreateThread(PrintClassList(“clist.text”)); } What does “CreateThread” do? Start independent thread running for a given procedure What is the behavior here? Now, you would actually see the class list This  should  behave as if there are two separate CPUs CPU1 CPU2 CPU1 CPU2 Time  CPU1 CPU2

Recommended for you

Operating Systems 1 (7/12) - Threads
Operating Systems 1 (7/12) - ThreadsOperating Systems 1 (7/12) - Threads
Operating Systems 1 (7/12) - Threads

The document discusses processes and threads in operating systems. It describes how processes contain multiple threads that can run concurrently on multicore systems. Each thread has its own execution state and context stored in a thread control block. When a thread is not actively running, its context is saved so it can resume execution later. The document provides examples of how threads are implemented in Windows and Linux operating systems.

threadspthreadsthreading
Operating system: threads(mulithreading,benefits of threads, types of thread)
Operating system: threads(mulithreading,benefits of threads, types of thread)Operating system: threads(mulithreading,benefits of threads, types of thread)
Operating system: threads(mulithreading,benefits of threads, types of thread)

Hello techies, this is a presentation by my team on operating system threads.. Reference::Galvin Hope this reference makes your learning experience well.

threadsonali hiranandanigoogle
Thread
ThreadThread
Thread

Threads are lightweight processes that improve application performance through parallelism. Each thread has its own program counter and stack but shares other resources like memory with other threads in a process. Using threads provides advantages like lower overhead context switching compared to processes and allows parallel execution on multi-core systems. There are two types of threads - user level threads managed by libraries and kernel level threads supported by the OS kernel. Threads have a life cycle that includes states like new, ready, running, blocked, and terminated.

Threads and processes Most modern OS’s (NT, modern UNIX, etc) therefore support two entities: the  process , which defines the address space and general process attributes (such as open files, etc.) the  thread , which defines a sequential execution stream within a process A thread is bound to a single process / address space address spaces, however, can have multiple threads executing within them sharing data between threads is cheap: all see the same address space creating threads is cheap too!
Single and Multithreaded Processes
Benefits Responsiveness - Interactive applications can be performing two tasks at the same time (rendering, spell checking) Resource Sharing - Sharing resources between threads is easy  Economy - Resource allocation between threads is fast (no protection issues) Utilization of MP Architectures - seamlessly assign multiple threads to multiple processors (if available). Future appears to be multi-core anyway.
Thread Design Space address space thread one thread/process many processes many threads/process many processes one thread/process one process many threads/process one process MS/DOS Java older UNIXes Mach, NT, Chorus, Linux, …

Recommended for you

Multithreading models
Multithreading modelsMultithreading models
Multithreading models

The document discusses three common multithreading models: many-to-one, one-to-one, and many-to-many. It also outlines some high-level program structures for multithreaded programs like boss/workers, pipeline, up-calls, and using version stamps.

Thread (Operating System)
Thread  (Operating System)Thread  (Operating System)
Thread (Operating System)

A thread is a portion of code that may be executed independently of the main program. For example, a program may have an open thread waiting for a specific event to occur or running a separate job, allowing the main program to perform other tasks. A program is capable of having multiple threads open at once and will either terminate or suspend them after a task is completed, or the program is closed.

THREADS of Operating System by Noman Zahid
THREADS of Operating System by Noman Zahid THREADS of Operating System by Noman Zahid
THREADS of Operating System by Noman Zahid

Threads provide concurrency within a process by allowing multiple flows of execution. Each thread has its own program counter, registers, and stack. There are two types of threads: user-level threads and kernel-level threads. User-level threads are managed in user space by a library and do not require kernel involvement for context switches. Kernel-level threads are known and scheduled by the operating system kernel, allowing simultaneous execution across multiple CPUs. While kernel threads have better coordination with the OS, user threads have less overhead during context switches.

(old) Process address space 0x00000000 0x7FFFFFFF address space code (text segment) static data (data segment) heap (dynamic allocated mem) stack (dynamic allocated mem) PC SP
(new) Address space with threads 0x00000000 0x7FFFFFFF address space code (text segment) static data (data segment) heap (dynamic allocated mem) thread 1 stack PC (T2) SP (T2) thread 2 stack thread 3 stack SP (T1) SP (T3) PC (T1) PC (T3) SP PC
Types of Threads
Thread types User threads : thread management done by user-level threads library. Kernel does not know about these threads Kernel threads : Supported by the Kernel and so more overhead than user threads Examples: Windows XP/2000, Solaris, Linux, Mac OS X User threads map into kernel threads

Recommended for you

Threading
ThreadingThreading
Threading

Threads are used by operating systems to allow multiple tasks to run simultaneously by allocating processor time between tasks. Threads maintain scheduling priorities and exception handlers independently of other threads. Threads are useful for dividing workload, providing rich user experiences, and handling operations that take a long time such as communicating over a network or with a database. Threads can be prioritized as high or low priority and can consume less memory than separate processes. Common thread operations include aborting, sleeping, joining, and waiting on threads.

c#microsoft visual studio.net framework
Os Threads
Os ThreadsOs Threads
Os Threads

This document discusses threads and threading models. It defines a thread as the basic unit of CPU utilization consisting of a program counter, stack, and registers. Threads allow for simultaneous execution of tasks within the same process by switching between threads rapidly. There are three main threading models: many-to-one maps many user threads to one kernel thread; one-to-one maps each user thread to its own kernel thread; many-to-many maps user threads to kernel threads in a variable manner. Popular thread libraries include POSIX pthreads and Win32 threads.

information technology
threads and its types ....in operating system ..
threads and its types ....in operating system ..threads and its types ....in operating system ..
threads and its types ....in operating system ..

A thread is a lightweight process that can be managed independently and improves performance through parallelism. It shares resources like data and code with other threads but has its own registers, stack, and counter. User-level threads are implemented at the application level and the kernel is unaware of them, handling them as single-threaded processes. They are faster to create than kernel threads but cannot take advantage of multiprocessing.

threadwhat is threads in oswhat is thread and its types
Multithreading Models Many-to-One: Many user-level threads mapped to single kernel thread If a thread blocks inside kernel, all the other threads cannot run Examples: Solaris Green Threads, GNU Pthreads
Multithreading Models One-to-One: Each user-level thread maps to kernel thread
Multithreading Models Many-to-Many: Allows many user level threads to be mapped to many kernel threads Allows the  operating system to create a sufficient number of kernel threads
Two-level Model Similar to M:M, except that it allows a user thread to be bound to kernel thread Examples IRIX HP-UX Tru64 UNIX Solaris 8 and earlier

Recommended for you

OS - Thread
OS - ThreadOS - Thread
OS - Thread

This document provides an overview of threads and processes. It defines a process as an executable file and thread as a function within a process. Each process has its own address space and resources, while each thread has its own program counter, stack, and registers. It discusses single-threaded and multi-threaded processes, as well as user space and kernel space. The document also covers concurrency on single-core and multi-core systems, different threading models (many-to-one, one-to-one, many-to-many), and benefits of multi-threading like responsiveness and resource sharing. Finally, it briefly discusses user threads, kernel threads, and common thread libraries.

Lecture 3 threads
Lecture 3   threadsLecture 3   threads
Lecture 3 threads

Threads provide concurrency within a process by allowing parallel execution. A thread is a flow of execution that has its own program counter, registers, and stack. Threads share code and data segments with other threads in the same process. There are two types: user threads managed by a library and kernel threads managed by the operating system kernel. Kernel threads allow true parallelism but have more overhead than user threads. Multithreading models include many-to-one, one-to-one, and many-to-many depending on how user threads map to kernel threads. Threads improve performance over single-threaded processes and allow for scalability across multiple CPUs.

operating systemsoperating systems threadsthreads
Multithreading models.ppt
Multithreading models.pptMultithreading models.ppt
Multithreading models.ppt

The document discusses three common multithreading models: many-to-one, one-to-one, and many-to-many. It also describes common high-level program structures for multithreaded programs like the boss/workers model, pipeline model, up-calls, and using version stamps to keep shared information consistent.

Threads Implementation Two ways: Provide library entirely in user space with no kernel support. Invoking function in the API ->local function call Kernel-level library supported by OS Invoking function in the API -> system call Three primary thread libraries: POSIX Pthreads (maybe KL or UL) Win32 threads (KL) Java threads (UL)
Threading Issues
Threading Issues Semantics of fork() and exec() system calls Thread cancellation Signal handling Thread pools Thread specific data Scheduler activations
Semantics of fork() and exec() Does  fork()  duplicate only the calling thread or all threads?

Recommended for you

multi-threading
multi-threadingmulti-threading
multi-threading

This document discusses threads and multi-threading in operating systems. It defines threads as parts of a program that can run simultaneously. The programmer must design the program such that threads do not interfere with each other. It compares threads to processes, noting that threads share resources like memory and address space within a process, while processes have separate address spaces. The document also outlines advantages of multi-threading like better CPU and cache utilization. Finally, it discusses user-level and kernel-level threads and different multi-threading models.

Treads
TreadsTreads
Treads

Threads allow a process to split into multiple execution paths to perform simultaneous tasks. A thread contains a program counter, stack, registers and thread ID. On a single CPU, threads switch rapidly via time-sharing, while on multi-core systems threads truly run simultaneously. Threads provide benefits like responsiveness, resource sharing, and better utilization of multiprocessing architectures. Threads can be implemented as user threads or kernel threads, with different threading models mapping user threads to kernel threads. Popular thread libraries include POSIX pthreads and Windows threads.

OS Process and Thread Concepts
OS Process and Thread ConceptsOS Process and Thread Concepts
OS Process and Thread Concepts

This lecture covers process and thread concepts in operating systems including scheduling criteria and algorithms. It discusses key process concepts like process state, process control block and CPU scheduling. Common scheduling algorithms like FCFS, SJF, priority and round robin are explained. Process scheduling queues and the producer-consumer problem are also summarized. Evaluation methods for scheduling algorithms like deterministic modeling, queueing models and simulation are briefly covered.

Thread Cancellation Terminating a thread before it has finished Two general approaches: Asynchronous cancellation terminates the target thread  immediately Deferred cancellation allows the target thread to periodically check if it should be cancelled
Signal Handling Signals are used in UNIX systems to notify a process that a particular event has occurred A signal handler is used to process signals Signal is generated by particular event Signal is delivered to a process Signal is handled Every signal maybe handled by either: A default signal handler A user-defined signal handler
Signal Handling In Multi-threaded programs, we have the following options: Deliver the signal to the thread to which the signal applies (e.g. synchronous signals) Deliver the signal to every thread in the process (e.g. terminate a process) Deliver the signal to certain threads in the process Assign a specific thread to receive all signals for the process In *nix: Kill –signal pid (for process), pthread_kill tid (for threads)
Thread Pools Do you remember the multithreading scenario in a web server? It has two problems: Time required to create the thread No bound on the number of threads

Recommended for you

Nandan Denim Limited
Nandan Denim LimitedNandan Denim Limited
Nandan Denim Limited

Nandan Denim Limited (NDL) is the second-largest textile company in India. Located in Gujarat, the textile hub of India, the Company is engaged in the manufacture of denims, cotton fabrics and khakis through fully integrated facilities. With a projected denim manufacturing capacity of 110 MMPA, NDL is currently the 2nd largest manufacturing facility in India. Machinery with latest technology from Germany and Japan, capable of producing wide range of denim fabrics. ~10% domestic fabric market share. NDL is a part of the Chiripal Group, a leading business conglomerate diversified across several businesses.

nandan denimnandan denim limited
Process and Threads in Linux - PPT
Process and Threads in Linux - PPTProcess and Threads in Linux - PPT
Process and Threads in Linux - PPT

Quontra Solutions offers Job oriented Linux online training with updated technologies. For more info about our Linux online training contact us directly. We are providing Linux online training to all students throughout worldwide by real time faculties. Our Linux training strengthens your skills and knowledge which will helps you to gain a competitive advantage in starting your career. Outclasses will help you to gain knowledge on real time scenario. It will be most use full to boost up your career. Our training sessions are designed in such a way that all the students can be convenient with the training schedules and course timings. Along with Training, we also conduct several mock interviews along with Job Placement Assistance. Attend Free Demo before joining the class. Our Features: • Real world projects to get practical based experience • Online tests to explore the resource learning • Experienced certified trainers as instructors • One to one personalized training with desktop access • Case studies and state of art library to access study material • Resume build assistance to win in interviews Contact us: Simson Andrew Email: info@quontrasolutions.com web: www.quontrasolutions.com

linux videoslinux tutorialslinux training
Operating System 5
Operating System 5Operating System 5
Operating System 5

The document discusses various CPU scheduling concepts and algorithms. It covers basic concepts like CPU-I/O burst cycles and scheduling criteria. It then describes common scheduling algorithms like first come first served (FCFS), shortest job first (SJF), priority scheduling, and round robin (RR). It also discusses more advanced topics like multi-level queue scheduling, multi-processor scheduling, and thread scheduling in Linux.

Thread Pools Create a number of threads in a pool where they await work Advantages: Usually slightly faster to service a request with an existing thread than create a new thread Allows the number of threads in the application(s) to be bound to the size of the pool
Thread Specific Data Allows each thread to have its own copy of data Useful when you do not have control over the thread creation process (i.e., when using a thread pool)
Scheduler Activations Both M:M and Two-level models require communication to maintain the appropriate number of kernel threads allocated to the application Use intermediate data structure called  LWP  (lightweight process) CPU Bound -> one LWP I/O Bound -> Multiple LWP
Scheduler Activations Scheduler activations provide  upcalls  - a communication mechanism from the kernel to the thread library This communication allows an application to maintain the correct of number kernel threads

Recommended for you

Terry Towel Production
Terry Towel ProductionTerry Towel Production
Terry Towel Production

A terry towel is a textile product which is made with loop pile on one or both sides generally covering the entire surface or forming strips, checks or other patterns. Special type of weaving technique is required for terry towel manufacturing. Terry towels are often very complex with yarns of different types and colors, in combination with various loop pile and flat structures. The name "terry" comes from the word "tirer" which means to pull out, referring to the pulled out by hand to make absorbent traditional. Turkish toweling Latin "vellus" meaning hair has the derivation "velour" which is the toweling with cut loops.There are many types of towel. Baby Towel, Bath Towel, Beach Towels, Golf Towels ,Hand Towel and Hotel Towels now used commonly.

Linux process management
Linux process managementLinux process management
Linux process management

The document discusses key concepts related to process management in Linux, including process lifecycle, states, memory segments, scheduling, and priorities. It explains that a process goes through creation, execution, termination, and removal phases repeatedly. Process states include running, stopped, interruptible, uninterruptible, and zombie. Process memory is made up of text, data, BSS, heap, and stack segments. Linux uses a O(1) CPU scheduling algorithm that scales well with process and processor counts.

Processes and threads
Processes and threadsProcesses and threads
Processes and threads

This document discusses processes and threads in Perl programming. It defines a process as an instance of a running program, while a thread is a flow of control through a program with a single execution point. Multiple threads can run within a single process and share resources, while processes run independently. The document compares processes and threads, and covers creating and managing threads, sharing data between threads, synchronization, and inter-process communication techniques in Perl like fork, pipe, and open.

threadsprogrammingperl
OS Examples
Windows XP Threads Implements the one-to-one mapping Each thread contains A thread id Register set Separate user and kernel stacks Private data storage area
Linux Threads Linux refers to them as tasks rather than threads Thread creation is done through clone() system call clone() allows a child task to share the address space of the parent task (process)
Conclusion Kernel threads: More robust than user-level threads Allow impersonation Easier to tune the OS CPU scheduler to handle multiple threads in a process A thread doing a wait on a kernel resource (like I/O) does not stop the process from running User-level threads A lot faster if programmed correctly Can be better tuned for the exact application Note that user-level threads can be done on any OS

Recommended for you

Types of Yarn and Spinning
Types of Yarn and SpinningTypes of Yarn and Spinning
Types of Yarn and Spinning

There are two main types of yarns: staple fiber yarn and filament yarn. Staple fiber yarn is made from short fibers and includes open end yarn and ring spun yarn. Filament yarn is made from continuous filaments and includes single filament and multifilament yarns. Rotor spinning and ring spinning are two processes for making yarn. Rotor spinning uses air and centrifugal force to twist fibers into yarn on a spinning rotor at high speeds. Ring spinning draws out roving, inserts twist, and winds yarn onto a bobbin simultaneously. Filament formation produces filament yarn by extruding liquid through spinneret holes and drying, twisting,

Processes and Processors in Distributed Systems
Processes and Processors in Distributed SystemsProcesses and Processors in Distributed Systems
Processes and Processors in Distributed Systems

The document discusses processes and processors in distributed systems. It covers threads, system models, processor allocation, scheduling, load balancing, and process migration. Threads are lightweight processes that share an address space and resources. There are advantages to using threads like handling signals and implementing producer-consumer problems. System models for distributed systems include workstations with local disks, diskless workstations, and a processor pool model. Processor allocation aims to maximize CPU utilization and minimize response times. Algorithms must consider overhead, complexity, and stability.

distributed operating systemsschedulingdistributed operating systems
Cotton Crop Presentation
Cotton Crop PresentationCotton Crop Presentation
Cotton Crop Presentation

This document summarizes information about cotton production in the United States. It notes that cotton is grown on fewer than 32,000 farms across 17 southern states, with 10.566 million acres planted in 2010. Cotton yield is measured in 480-pound bales, with the average 2005-2009 yield being 826 pounds of lint per acre. The cotton crop requires fertility, is planted and grows through vegetative stages before flowering and boll development over several months. Harvesting is a critical process where cotton is mechanically picked or stripped before ginning and baling.

cottoncropsproduction
Conclusion Each thread shares everything with all the other threads in the process They can read/write the exact same variables, so they need to synchronize themselves They can access each other’s runtime stack, so be very careful if you communicate using runtime stack variables Each thread should be able to retrieve a unique thread id that it can use to access  thread local storage Multi-threading is great, but use it wisely

More Related Content

What's hot

Thread
ThreadThread
Thread
Mohd Arif
 
Chapter 4 - Threads
Chapter 4 - ThreadsChapter 4 - Threads
Chapter 4 - Threads
Wayne Jones Jnr
 
Thread scheduling in Operating Systems
Thread scheduling in Operating SystemsThread scheduling in Operating Systems
Thread scheduling in Operating Systems
Nitish Gulati
 
Thread management
Thread management Thread management
Thread management
Ayaan Adeel
 
Threads .ppt
Threads .pptThreads .ppt
Threads .ppt
meet darji
 
Threads
ThreadsThreads
Threads
Shivam Singh
 
Operating Systems 1 (7/12) - Threads
Operating Systems 1 (7/12) - ThreadsOperating Systems 1 (7/12) - Threads
Operating Systems 1 (7/12) - Threads
Peter Tröger
 
Operating system: threads(mulithreading,benefits of threads, types of thread)
Operating system: threads(mulithreading,benefits of threads, types of thread)Operating system: threads(mulithreading,benefits of threads, types of thread)
Operating system: threads(mulithreading,benefits of threads, types of thread)
sonuu__
 
Thread
ThreadThread
Multithreading models
Multithreading modelsMultithreading models
Multithreading models
anoopkrishna2
 
Thread (Operating System)
Thread  (Operating System)Thread  (Operating System)
Thread (Operating System)
kiran Patel
 
THREADS of Operating System by Noman Zahid
THREADS of Operating System by Noman Zahid THREADS of Operating System by Noman Zahid
THREADS of Operating System by Noman Zahid
noman zahid
 
Threading
ThreadingThreading
Os Threads
Os ThreadsOs Threads
Os Threads
Salman Memon
 
threads and its types ....in operating system ..
threads and its types ....in operating system ..threads and its types ....in operating system ..
threads and its types ....in operating system ..
Nimrakhan89
 
OS - Thread
OS - ThreadOS - Thread
OS - Thread
vinay arora
 
Lecture 3 threads
Lecture 3   threadsLecture 3   threads
Lecture 3 threads
Kumbirai Junior Muzavazi
 
Multithreading models.ppt
Multithreading models.pptMultithreading models.ppt
Multithreading models.ppt
Luis Goldster
 
multi-threading
multi-threadingmulti-threading
multi-threading
Ezzat Gul
 
Treads
TreadsTreads

What's hot (20)

Thread
ThreadThread
Thread
 
Chapter 4 - Threads
Chapter 4 - ThreadsChapter 4 - Threads
Chapter 4 - Threads
 
Thread scheduling in Operating Systems
Thread scheduling in Operating SystemsThread scheduling in Operating Systems
Thread scheduling in Operating Systems
 
Thread management
Thread management Thread management
Thread management
 
Threads .ppt
Threads .pptThreads .ppt
Threads .ppt
 
Threads
ThreadsThreads
Threads
 
Operating Systems 1 (7/12) - Threads
Operating Systems 1 (7/12) - ThreadsOperating Systems 1 (7/12) - Threads
Operating Systems 1 (7/12) - Threads
 
Operating system: threads(mulithreading,benefits of threads, types of thread)
Operating system: threads(mulithreading,benefits of threads, types of thread)Operating system: threads(mulithreading,benefits of threads, types of thread)
Operating system: threads(mulithreading,benefits of threads, types of thread)
 
Thread
ThreadThread
Thread
 
Multithreading models
Multithreading modelsMultithreading models
Multithreading models
 
Thread (Operating System)
Thread  (Operating System)Thread  (Operating System)
Thread (Operating System)
 
THREADS of Operating System by Noman Zahid
THREADS of Operating System by Noman Zahid THREADS of Operating System by Noman Zahid
THREADS of Operating System by Noman Zahid
 
Threading
ThreadingThreading
Threading
 
Os Threads
Os ThreadsOs Threads
Os Threads
 
threads and its types ....in operating system ..
threads and its types ....in operating system ..threads and its types ....in operating system ..
threads and its types ....in operating system ..
 
OS - Thread
OS - ThreadOS - Thread
OS - Thread
 
Lecture 3 threads
Lecture 3   threadsLecture 3   threads
Lecture 3 threads
 
Multithreading models.ppt
Multithreading models.pptMultithreading models.ppt
Multithreading models.ppt
 
multi-threading
multi-threadingmulti-threading
multi-threading
 
Treads
TreadsTreads
Treads
 

Viewers also liked

OS Process and Thread Concepts
OS Process and Thread ConceptsOS Process and Thread Concepts
OS Process and Thread Concepts
sgpraju
 
Nandan Denim Limited
Nandan Denim LimitedNandan Denim Limited
Nandan Denim Limited
Zil Shah
 
Process and Threads in Linux - PPT
Process and Threads in Linux - PPTProcess and Threads in Linux - PPT
Process and Threads in Linux - PPT
QUONTRASOLUTIONS
 
Operating System 5
Operating System 5Operating System 5
Operating System 5
tech2click
 
Terry Towel Production
Terry Towel ProductionTerry Towel Production
Terry Towel Production
Azmir Latif Beg
 
Linux process management
Linux process managementLinux process management
Linux process management
Raghu nath
 
Processes and threads
Processes and threadsProcesses and threads
Types of Yarn and Spinning
Types of Yarn and SpinningTypes of Yarn and Spinning
Types of Yarn and Spinning
RaNa ALi HaiDer
 
Processes and Processors in Distributed Systems
Processes and Processors in Distributed SystemsProcesses and Processors in Distributed Systems
Processes and Processors in Distributed Systems
Dr Sandeep Kumar Poonia
 
Cotton Crop Presentation
Cotton Crop PresentationCotton Crop Presentation
Cotton Crop Presentation
David Taylor
 
Cotton ppt
Cotton pptCotton ppt
Cotton ppt
Varun Devang
 
Operating Systems
Operating SystemsOperating Systems
Operating Systems
Harshith Meela
 
Operating system.ppt (1)
Operating system.ppt (1)Operating system.ppt (1)
Operating system.ppt (1)
Vaibhav Bajaj
 
Chemistry project PREPARATION OF RAYON FROM FILTER PAPER
Chemistry project PREPARATION OF RAYON FROM FILTER PAPER Chemistry project PREPARATION OF RAYON FROM FILTER PAPER
Chemistry project PREPARATION OF RAYON FROM FILTER PAPER
issaq pasha
 
Classification of yarn yarn classification. Textile yarn. Yarn count.
Classification of yarn   yarn classification. Textile yarn. Yarn count. Classification of yarn   yarn classification. Textile yarn. Yarn count.
Classification of yarn yarn classification. Textile yarn. Yarn count.
Vaibhav Mathankar
 

Viewers also liked (15)

OS Process and Thread Concepts
OS Process and Thread ConceptsOS Process and Thread Concepts
OS Process and Thread Concepts
 
Nandan Denim Limited
Nandan Denim LimitedNandan Denim Limited
Nandan Denim Limited
 
Process and Threads in Linux - PPT
Process and Threads in Linux - PPTProcess and Threads in Linux - PPT
Process and Threads in Linux - PPT
 
Operating System 5
Operating System 5Operating System 5
Operating System 5
 
Terry Towel Production
Terry Towel ProductionTerry Towel Production
Terry Towel Production
 
Linux process management
Linux process managementLinux process management
Linux process management
 
Processes and threads
Processes and threadsProcesses and threads
Processes and threads
 
Types of Yarn and Spinning
Types of Yarn and SpinningTypes of Yarn and Spinning
Types of Yarn and Spinning
 
Processes and Processors in Distributed Systems
Processes and Processors in Distributed SystemsProcesses and Processors in Distributed Systems
Processes and Processors in Distributed Systems
 
Cotton Crop Presentation
Cotton Crop PresentationCotton Crop Presentation
Cotton Crop Presentation
 
Cotton ppt
Cotton pptCotton ppt
Cotton ppt
 
Operating Systems
Operating SystemsOperating Systems
Operating Systems
 
Operating system.ppt (1)
Operating system.ppt (1)Operating system.ppt (1)
Operating system.ppt (1)
 
Chemistry project PREPARATION OF RAYON FROM FILTER PAPER
Chemistry project PREPARATION OF RAYON FROM FILTER PAPER Chemistry project PREPARATION OF RAYON FROM FILTER PAPER
Chemistry project PREPARATION OF RAYON FROM FILTER PAPER
 
Classification of yarn yarn classification. Textile yarn. Yarn count.
Classification of yarn   yarn classification. Textile yarn. Yarn count. Classification of yarn   yarn classification. Textile yarn. Yarn count.
Classification of yarn yarn classification. Textile yarn. Yarn count.
 

Similar to Operating System 4

Os
OsOs
Topic 4- processes.pptx
Topic 4- processes.pptxTopic 4- processes.pptx
Topic 4- processes.pptx
DanishMahmood23
 
Chapter 6 os
Chapter 6 osChapter 6 os
Chapter 6 os
AbDul ThaYyal
 
Visual comparison of Unix-like systems & Virtualisation
Visual comparison of Unix-like systems & VirtualisationVisual comparison of Unix-like systems & Virtualisation
Visual comparison of Unix-like systems & Virtualisation
wangyuanyi
 
CH04.pdf
CH04.pdfCH04.pdf
CH04.pdf
ImranKhan880955
 
Evolution of the Windows Kernel Architecture, by Dave Probert
Evolution of the Windows Kernel Architecture, by Dave ProbertEvolution of the Windows Kernel Architecture, by Dave Probert
Evolution of the Windows Kernel Architecture, by Dave Probert
yang
 
Oct2009
Oct2009Oct2009
Oct2009
guest81ab2b4
 
Chapter04 new
Chapter04 newChapter04 new
Chapter04 new
vmummaneni
 
Chorus - Distributed Operating System [ case study ]
Chorus - Distributed Operating System [ case study ]Chorus - Distributed Operating System [ case study ]
Chorus - Distributed Operating System [ case study ]
Akhil Nadh PC
 
Concept of thread, multi thread, tcb
Concept of thread, multi thread, tcbConcept of thread, multi thread, tcb
Concept of thread, multi thread, tcb
Kanza batool
 
WEEK07operatingsystemdepartmentofsoftwareengineering.pptx
WEEK07operatingsystemdepartmentofsoftwareengineering.pptxWEEK07operatingsystemdepartmentofsoftwareengineering.pptx
WEEK07operatingsystemdepartmentofsoftwareengineering.pptx
babayaga920391
 
Lecture1
Lecture1Lecture1
Lecture1
Asad Abbas
 
4.Process.ppt
4.Process.ppt4.Process.ppt
4.Process.ppt
AkfeteAssefa
 
OS Module-2.pptx
OS Module-2.pptxOS Module-2.pptx
OS Module-2.pptx
bleh23
 
Introto netthreads-090906214344-phpapp01
Introto netthreads-090906214344-phpapp01Introto netthreads-090906214344-phpapp01
Introto netthreads-090906214344-phpapp01
Aravindharamanan S
 
Parallel architecture
Parallel architectureParallel architecture
Parallel architecture
Mr SMAK
 
Slot02 concurrency1
Slot02 concurrency1Slot02 concurrency1
Slot02 concurrency1
Viên Mai
 
Parallel Processing (Part 2)
Parallel Processing (Part 2)Parallel Processing (Part 2)
Parallel Processing (Part 2)
Ajeng Savitri
 
Distributed computing
Distributed computingDistributed computing
Distributed computing
Deepak John
 
2337610
23376102337610
2337610
hantfhan
 

Similar to Operating System 4 (20)

Os
OsOs
Os
 
Topic 4- processes.pptx
Topic 4- processes.pptxTopic 4- processes.pptx
Topic 4- processes.pptx
 
Chapter 6 os
Chapter 6 osChapter 6 os
Chapter 6 os
 
Visual comparison of Unix-like systems & Virtualisation
Visual comparison of Unix-like systems & VirtualisationVisual comparison of Unix-like systems & Virtualisation
Visual comparison of Unix-like systems & Virtualisation
 
CH04.pdf
CH04.pdfCH04.pdf
CH04.pdf
 
Evolution of the Windows Kernel Architecture, by Dave Probert
Evolution of the Windows Kernel Architecture, by Dave ProbertEvolution of the Windows Kernel Architecture, by Dave Probert
Evolution of the Windows Kernel Architecture, by Dave Probert
 
Oct2009
Oct2009Oct2009
Oct2009
 
Chapter04 new
Chapter04 newChapter04 new
Chapter04 new
 
Chorus - Distributed Operating System [ case study ]
Chorus - Distributed Operating System [ case study ]Chorus - Distributed Operating System [ case study ]
Chorus - Distributed Operating System [ case study ]
 
Concept of thread, multi thread, tcb
Concept of thread, multi thread, tcbConcept of thread, multi thread, tcb
Concept of thread, multi thread, tcb
 
WEEK07operatingsystemdepartmentofsoftwareengineering.pptx
WEEK07operatingsystemdepartmentofsoftwareengineering.pptxWEEK07operatingsystemdepartmentofsoftwareengineering.pptx
WEEK07operatingsystemdepartmentofsoftwareengineering.pptx
 
Lecture1
Lecture1Lecture1
Lecture1
 
4.Process.ppt
4.Process.ppt4.Process.ppt
4.Process.ppt
 
OS Module-2.pptx
OS Module-2.pptxOS Module-2.pptx
OS Module-2.pptx
 
Introto netthreads-090906214344-phpapp01
Introto netthreads-090906214344-phpapp01Introto netthreads-090906214344-phpapp01
Introto netthreads-090906214344-phpapp01
 
Parallel architecture
Parallel architectureParallel architecture
Parallel architecture
 
Slot02 concurrency1
Slot02 concurrency1Slot02 concurrency1
Slot02 concurrency1
 
Parallel Processing (Part 2)
Parallel Processing (Part 2)Parallel Processing (Part 2)
Parallel Processing (Part 2)
 
Distributed computing
Distributed computingDistributed computing
Distributed computing
 
2337610
23376102337610
2337610
 

More from tech2click

Process Synchronization And Deadlocks
Process Synchronization And DeadlocksProcess Synchronization And Deadlocks
Process Synchronization And Deadlocks
tech2click
 
Ch13
Ch13Ch13
Ch12
Ch12Ch12
Ch11
Ch11Ch11
Ch10
Ch10Ch10
Ch8
Ch8Ch8
Tutorial4 Threads
Tutorial4  ThreadsTutorial4  Threads
Tutorial4 Threads
tech2click
 
Mid1 Revision
Mid1  RevisionMid1  Revision
Mid1 Revision
tech2click
 
Operating System 3
Operating System 3Operating System 3
Operating System 3
tech2click
 
Tutorial 2
Tutorial 2Tutorial 2
Tutorial 2
tech2click
 
Operating System 2
Operating System 2Operating System 2
Operating System 2
tech2click
 
Rootkit
RootkitRootkit
Rootkit
tech2click
 

More from tech2click (12)

Process Synchronization And Deadlocks
Process Synchronization And DeadlocksProcess Synchronization And Deadlocks
Process Synchronization And Deadlocks
 
Ch13
Ch13Ch13
Ch13
 
Ch12
Ch12Ch12
Ch12
 
Ch11
Ch11Ch11
Ch11
 
Ch10
Ch10Ch10
Ch10
 
Ch8
Ch8Ch8
Ch8
 
Tutorial4 Threads
Tutorial4  ThreadsTutorial4  Threads
Tutorial4 Threads
 
Mid1 Revision
Mid1  RevisionMid1  Revision
Mid1 Revision
 
Operating System 3
Operating System 3Operating System 3
Operating System 3
 
Tutorial 2
Tutorial 2Tutorial 2
Tutorial 2
 
Operating System 2
Operating System 2Operating System 2
Operating System 2
 
Rootkit
RootkitRootkit
Rootkit
 

Recently uploaded

GDG Cloud Southlake #34: Neatsun Ziv: Automating Appsec
GDG Cloud Southlake #34: Neatsun Ziv: Automating AppsecGDG Cloud Southlake #34: Neatsun Ziv: Automating Appsec
GDG Cloud Southlake #34: Neatsun Ziv: Automating Appsec
James Anderson
 
5G bootcamp Sep 2020 (NPI initiative).pptx
5G bootcamp Sep 2020 (NPI initiative).pptx5G bootcamp Sep 2020 (NPI initiative).pptx
5G bootcamp Sep 2020 (NPI initiative).pptx
SATYENDRA100
 
Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...
BookNet Canada
 
“Intel’s Approach to Operationalizing AI in the Manufacturing Sector,” a Pres...
“Intel’s Approach to Operationalizing AI in the Manufacturing Sector,” a Pres...“Intel’s Approach to Operationalizing AI in the Manufacturing Sector,” a Pres...
“Intel’s Approach to Operationalizing AI in the Manufacturing Sector,” a Pres...
Edge AI and Vision Alliance
 
Details of description part II: Describing images in practice - Tech Forum 2024
Details of description part II: Describing images in practice - Tech Forum 2024Details of description part II: Describing images in practice - Tech Forum 2024
Details of description part II: Describing images in practice - Tech Forum 2024
BookNet Canada
 
@Call @Girls Thiruvananthapuram 🚒 XXXXXXXXXX 🚒 Priya Sharma Beautiful And Cu...
@Call @Girls Thiruvananthapuram  🚒 XXXXXXXXXX 🚒 Priya Sharma Beautiful And Cu...@Call @Girls Thiruvananthapuram  🚒 XXXXXXXXXX 🚒 Priya Sharma Beautiful And Cu...
@Call @Girls Thiruvananthapuram 🚒 XXXXXXXXXX 🚒 Priya Sharma Beautiful And Cu...
kantakumariji156
 
How Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdfHow Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdf
HackersList
 
Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...
Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...
Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...
Erasmo Purificato
 
7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf
Enterprise Wired
 
Running a Go App in Kubernetes: CPU Impacts
Running a Go App in Kubernetes: CPU ImpactsRunning a Go App in Kubernetes: CPU Impacts
Running a Go App in Kubernetes: CPU Impacts
ScyllaDB
 
Quality Patents: Patents That Stand the Test of Time
Quality Patents: Patents That Stand the Test of TimeQuality Patents: Patents That Stand the Test of Time
Quality Patents: Patents That Stand the Test of Time
Aurora Consulting
 
What's Next Web Development Trends to Watch.pdf
What's Next Web Development Trends to Watch.pdfWhat's Next Web Development Trends to Watch.pdf
What's Next Web Development Trends to Watch.pdf
SeasiaInfotech2
 
Why do You Have to Redesign?_Redesign Challenge Day 1
Why do You Have to Redesign?_Redesign Challenge Day 1Why do You Have to Redesign?_Redesign Challenge Day 1
Why do You Have to Redesign?_Redesign Challenge Day 1
FellyciaHikmahwarani
 
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design ApproachesKnowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
Earley Information Science
 
MYIR Product Brochure - A Global Provider of Embedded SOMs & Solutions
MYIR Product Brochure - A Global Provider of Embedded SOMs & SolutionsMYIR Product Brochure - A Global Provider of Embedded SOMs & Solutions
MYIR Product Brochure - A Global Provider of Embedded SOMs & Solutions
Linda Zhang
 
What's New in Copilot for Microsoft365 May 2024.pptx
What's New in Copilot for Microsoft365 May 2024.pptxWhat's New in Copilot for Microsoft365 May 2024.pptx
What's New in Copilot for Microsoft365 May 2024.pptx
Stephanie Beckett
 
一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理
一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理
一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理
uuuot
 
Recent Advancements in the NIST-JARVIS Infrastructure
Recent Advancements in the NIST-JARVIS InfrastructureRecent Advancements in the NIST-JARVIS Infrastructure
Recent Advancements in the NIST-JARVIS Infrastructure
KAMAL CHOUDHARY
 
Implementations of Fused Deposition Modeling in real world
Implementations of Fused Deposition Modeling  in real worldImplementations of Fused Deposition Modeling  in real world
Implementations of Fused Deposition Modeling in real world
Emerging Tech
 
AC Atlassian Coimbatore Session Slides( 22/06/2024)
AC Atlassian Coimbatore Session Slides( 22/06/2024)AC Atlassian Coimbatore Session Slides( 22/06/2024)
AC Atlassian Coimbatore Session Slides( 22/06/2024)
apoorva2579
 

Recently uploaded (20)

GDG Cloud Southlake #34: Neatsun Ziv: Automating Appsec
GDG Cloud Southlake #34: Neatsun Ziv: Automating AppsecGDG Cloud Southlake #34: Neatsun Ziv: Automating Appsec
GDG Cloud Southlake #34: Neatsun Ziv: Automating Appsec
 
5G bootcamp Sep 2020 (NPI initiative).pptx
5G bootcamp Sep 2020 (NPI initiative).pptx5G bootcamp Sep 2020 (NPI initiative).pptx
5G bootcamp Sep 2020 (NPI initiative).pptx
 
Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...
 
“Intel’s Approach to Operationalizing AI in the Manufacturing Sector,” a Pres...
“Intel’s Approach to Operationalizing AI in the Manufacturing Sector,” a Pres...“Intel’s Approach to Operationalizing AI in the Manufacturing Sector,” a Pres...
“Intel’s Approach to Operationalizing AI in the Manufacturing Sector,” a Pres...
 
Details of description part II: Describing images in practice - Tech Forum 2024
Details of description part II: Describing images in practice - Tech Forum 2024Details of description part II: Describing images in practice - Tech Forum 2024
Details of description part II: Describing images in practice - Tech Forum 2024
 
@Call @Girls Thiruvananthapuram 🚒 XXXXXXXXXX 🚒 Priya Sharma Beautiful And Cu...
@Call @Girls Thiruvananthapuram  🚒 XXXXXXXXXX 🚒 Priya Sharma Beautiful And Cu...@Call @Girls Thiruvananthapuram  🚒 XXXXXXXXXX 🚒 Priya Sharma Beautiful And Cu...
@Call @Girls Thiruvananthapuram 🚒 XXXXXXXXXX 🚒 Priya Sharma Beautiful And Cu...
 
How Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdfHow Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdf
 
Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...
Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...
Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...
 
7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf
 
Running a Go App in Kubernetes: CPU Impacts
Running a Go App in Kubernetes: CPU ImpactsRunning a Go App in Kubernetes: CPU Impacts
Running a Go App in Kubernetes: CPU Impacts
 
Quality Patents: Patents That Stand the Test of Time
Quality Patents: Patents That Stand the Test of TimeQuality Patents: Patents That Stand the Test of Time
Quality Patents: Patents That Stand the Test of Time
 
What's Next Web Development Trends to Watch.pdf
What's Next Web Development Trends to Watch.pdfWhat's Next Web Development Trends to Watch.pdf
What's Next Web Development Trends to Watch.pdf
 
Why do You Have to Redesign?_Redesign Challenge Day 1
Why do You Have to Redesign?_Redesign Challenge Day 1Why do You Have to Redesign?_Redesign Challenge Day 1
Why do You Have to Redesign?_Redesign Challenge Day 1
 
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design ApproachesKnowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
 
MYIR Product Brochure - A Global Provider of Embedded SOMs & Solutions
MYIR Product Brochure - A Global Provider of Embedded SOMs & SolutionsMYIR Product Brochure - A Global Provider of Embedded SOMs & Solutions
MYIR Product Brochure - A Global Provider of Embedded SOMs & Solutions
 
What's New in Copilot for Microsoft365 May 2024.pptx
What's New in Copilot for Microsoft365 May 2024.pptxWhat's New in Copilot for Microsoft365 May 2024.pptx
What's New in Copilot for Microsoft365 May 2024.pptx
 
一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理
一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理
一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理
 
Recent Advancements in the NIST-JARVIS Infrastructure
Recent Advancements in the NIST-JARVIS InfrastructureRecent Advancements in the NIST-JARVIS Infrastructure
Recent Advancements in the NIST-JARVIS Infrastructure
 
Implementations of Fused Deposition Modeling in real world
Implementations of Fused Deposition Modeling  in real worldImplementations of Fused Deposition Modeling  in real world
Implementations of Fused Deposition Modeling in real world
 
AC Atlassian Coimbatore Session Slides( 22/06/2024)
AC Atlassian Coimbatore Session Slides( 22/06/2024)AC Atlassian Coimbatore Session Slides( 22/06/2024)
AC Atlassian Coimbatore Session Slides( 22/06/2024)
 

Operating System 4

  • 1. Chapter 4: Threads
  • 2. What’s in a process? A process consists of (at least): an address space the code for the running program the data for the running program an execution stack and stack pointer (SP) traces state of procedure calls made the program counter (PC), indicating the next instruction a set of general-purpose processor registers and their values a set of OS resources open files, network connections, sound channels, …
  • 3. Concurrency Imagine a web server, which might like to handle multiple requests concurrently While waiting for the credit card server to approve a purchase for one client, it could be retrieving the data requested by another client from disk, and assembling the response for a third client from cached information Imagine a web client (browser), which might like to initiate multiple requests concurrently The IT home page has 10 “src= …” html commands, each of which is going to involve a lot of sitting around! Wouldn’t it be nice to be able to launch these requests concurrently? Imagine a parallel program running on a multiprocessor, which might like to employ “physical concurrency” For example, multiplying a large matrix – split the output matrix into k regions and compute the entries in each region concurrently using k processors
  • 4. What’s needed? In each of these examples of concurrency (web server, web client, parallel program): Everybody wants to run the same code Everybody wants to access the same data Everybody has the same privileges (most of the time) Everybody uses the same resources (open files, network connections, etc.) But you’d like to have multiple hardware execution states: an execution stack and stack pointer (SP) traces state of procedure calls made the program counter (PC), indicating the next instruction a set of general-purpose processor registers and their values
  • 5. How could we achieve this? Given the process abstraction as we know it: fork several processes cause each to map to the same physical memory to share data This is really inefficient!! space: PCB, page tables, etc. time: creating OS structures, fork and copy address space, etc. So any support that the OS can give for doing multi-threaded programming is a win
  • 6. Can we do better? Key idea: separate the concept of a process (address space, etc.) … from that of a minimal “ thread of control ” (execution state: PC, etc.) This execution state is usually called a thread , or sometimes, a lightweight process
  • 7. Single-Threaded Example Imagine the following C program: main() { ComputePI(“pi.txt”); PrintClassList(“clist.text”); } What is the behavior here? Program would never print out class list Why? ComputePI would never finish
  • 8. Use of Threads Version of program with Threads: main() { CreateThread(ComputePI(“pi.txt”)); CreateThread(PrintClassList(“clist.text”)); } What does “CreateThread” do? Start independent thread running for a given procedure What is the behavior here? Now, you would actually see the class list This should behave as if there are two separate CPUs CPU1 CPU2 CPU1 CPU2 Time CPU1 CPU2
  • 9. Threads and processes Most modern OS’s (NT, modern UNIX, etc) therefore support two entities: the process , which defines the address space and general process attributes (such as open files, etc.) the thread , which defines a sequential execution stream within a process A thread is bound to a single process / address space address spaces, however, can have multiple threads executing within them sharing data between threads is cheap: all see the same address space creating threads is cheap too!
  • 11. Benefits Responsiveness - Interactive applications can be performing two tasks at the same time (rendering, spell checking) Resource Sharing - Sharing resources between threads is easy Economy - Resource allocation between threads is fast (no protection issues) Utilization of MP Architectures - seamlessly assign multiple threads to multiple processors (if available). Future appears to be multi-core anyway.
  • 12. Thread Design Space address space thread one thread/process many processes many threads/process many processes one thread/process one process many threads/process one process MS/DOS Java older UNIXes Mach, NT, Chorus, Linux, …
  • 13. (old) Process address space 0x00000000 0x7FFFFFFF address space code (text segment) static data (data segment) heap (dynamic allocated mem) stack (dynamic allocated mem) PC SP
  • 14. (new) Address space with threads 0x00000000 0x7FFFFFFF address space code (text segment) static data (data segment) heap (dynamic allocated mem) thread 1 stack PC (T2) SP (T2) thread 2 stack thread 3 stack SP (T1) SP (T3) PC (T1) PC (T3) SP PC
  • 16. Thread types User threads : thread management done by user-level threads library. Kernel does not know about these threads Kernel threads : Supported by the Kernel and so more overhead than user threads Examples: Windows XP/2000, Solaris, Linux, Mac OS X User threads map into kernel threads
  • 17. Multithreading Models Many-to-One: Many user-level threads mapped to single kernel thread If a thread blocks inside kernel, all the other threads cannot run Examples: Solaris Green Threads, GNU Pthreads
  • 18. Multithreading Models One-to-One: Each user-level thread maps to kernel thread
  • 19. Multithreading Models Many-to-Many: Allows many user level threads to be mapped to many kernel threads Allows the operating system to create a sufficient number of kernel threads
  • 20. Two-level Model Similar to M:M, except that it allows a user thread to be bound to kernel thread Examples IRIX HP-UX Tru64 UNIX Solaris 8 and earlier
  • 21. Threads Implementation Two ways: Provide library entirely in user space with no kernel support. Invoking function in the API ->local function call Kernel-level library supported by OS Invoking function in the API -> system call Three primary thread libraries: POSIX Pthreads (maybe KL or UL) Win32 threads (KL) Java threads (UL)
  • 23. Threading Issues Semantics of fork() and exec() system calls Thread cancellation Signal handling Thread pools Thread specific data Scheduler activations
  • 24. Semantics of fork() and exec() Does fork() duplicate only the calling thread or all threads?
  • 25. Thread Cancellation Terminating a thread before it has finished Two general approaches: Asynchronous cancellation terminates the target thread immediately Deferred cancellation allows the target thread to periodically check if it should be cancelled
  • 26. Signal Handling Signals are used in UNIX systems to notify a process that a particular event has occurred A signal handler is used to process signals Signal is generated by particular event Signal is delivered to a process Signal is handled Every signal maybe handled by either: A default signal handler A user-defined signal handler
  • 27. Signal Handling In Multi-threaded programs, we have the following options: Deliver the signal to the thread to which the signal applies (e.g. synchronous signals) Deliver the signal to every thread in the process (e.g. terminate a process) Deliver the signal to certain threads in the process Assign a specific thread to receive all signals for the process In *nix: Kill –signal pid (for process), pthread_kill tid (for threads)
  • 28. Thread Pools Do you remember the multithreading scenario in a web server? It has two problems: Time required to create the thread No bound on the number of threads
  • 29. Thread Pools Create a number of threads in a pool where they await work Advantages: Usually slightly faster to service a request with an existing thread than create a new thread Allows the number of threads in the application(s) to be bound to the size of the pool
  • 30. Thread Specific Data Allows each thread to have its own copy of data Useful when you do not have control over the thread creation process (i.e., when using a thread pool)
  • 31. Scheduler Activations Both M:M and Two-level models require communication to maintain the appropriate number of kernel threads allocated to the application Use intermediate data structure called LWP (lightweight process) CPU Bound -> one LWP I/O Bound -> Multiple LWP
  • 32. Scheduler Activations Scheduler activations provide upcalls - a communication mechanism from the kernel to the thread library This communication allows an application to maintain the correct of number kernel threads
  • 34. Windows XP Threads Implements the one-to-one mapping Each thread contains A thread id Register set Separate user and kernel stacks Private data storage area
  • 35. Linux Threads Linux refers to them as tasks rather than threads Thread creation is done through clone() system call clone() allows a child task to share the address space of the parent task (process)
  • 36. Conclusion Kernel threads: More robust than user-level threads Allow impersonation Easier to tune the OS CPU scheduler to handle multiple threads in a process A thread doing a wait on a kernel resource (like I/O) does not stop the process from running User-level threads A lot faster if programmed correctly Can be better tuned for the exact application Note that user-level threads can be done on any OS
  • 37. Conclusion Each thread shares everything with all the other threads in the process They can read/write the exact same variables, so they need to synchronize themselves They can access each other’s runtime stack, so be very careful if you communicate using runtime stack variables Each thread should be able to retrieve a unique thread id that it can use to access thread local storage Multi-threading is great, but use it wisely