SlideShare a Scribd company logo
MULTI-THREADED  PROGRAMMING Reported by: N ikko  D elumen M ary  J oy  T apar
4.1 OVERVIEW Thread  – basic unit of CPU utilization; it comprises a thread ID, a program counter, a register set, and a stack.
4.1.1 MOTIVATION Many software packages that run on modern desktop PCs are multithreaded.  Example:  A word processor may have a thread for displaying graphics, another for responding to keystrokes, and a third is for performing spelling and grammar checking in background.
thread thread Single-threaded process Multi-threaded process
Recall from CHAPTER3  “ RPCs allow interprocess communication by providing a communication mechanism similar to ordinary function or procedure calls.” Typically, RPC servers are multithreaded. When server receives a message, it services the message using a separate thread.
4.1.2 BENEFITS Responsiveness.   Multithreading an interactive application may allow a program to continue running even if part of it is blocked or is performing a lengthy operation, thereby increasing responsiveness to the user.
Resource Sharing.  By default, threads share the memory and the resources of the process to which they belong. Economy.  Allocating memory and resources for process creation is costly. Because threads share resources of the process to which they belong, it is more economical to create and context-switch threads.
Utilization of multiprocessor architectures.  Threads may be running in parallel on different processors. A single-threaded process can only run on one CPU, no matter how many are available.
4.2 MULTI-THREADING MODELS Support for threads may be provided either at the user level, for user threads, or by the kernel, for kernel threads.
4.2.1 Many-to-One Model User thread Kernel thread
4.2.2 One-to-One Model User thread Kernel thread
Two-level Model User thread Kernel thread
4.2.3 Many-to-Many Model User thread Kernel thread
4.3 THREAD LIBRARIES A  Thread Library  provides the programmer an API for creating and managing threads.
Two Primary Ways of Implementing a Thread Library To provide a library entirely in user with no kernel support. All code and data structures for the library exist in user space. To implement a kernel-level library supported directly by the operating system. Code and data structures for the library exist in kernel space.
4.3.1 PTHREADS Pthreads  refers to the POSIX standard (IEEE 1003.1c) defining an API for thread creation and synchronization.
#include <pthread.h> #include <stdio.h> int sum; void *runner(void *param); int main(int argc, char *argv[]) { pthread.t tid; pthread_attr_t attr; if (argc !=2){ fprintf(stderr,”usage: a.out(integer value>\n”); return -1; } if (atoi (argv[1]) < 0) { fprintf(stderr,”%d must be >= 0\n”, atoi (argv[1])); return -1; } pthread_attr_init(&attr); pthread_create (&tid, &attr, runner, argv[1]); pthread_join (tid,NULL); printf(“sum=%d\n”, sum); } void *runner(void *param) { int i, upper = atoi(param) sum = 0; for (i=1; i<=upper; i++) sum += I; pthread_exit (0); }
4.3.2 WIN32 THREADS The technique of creating threads using Win32 thread library is similar to the Pthreads technique in several ways.
#include <windows.h> #include <stdio.h> DWORD Sum; DWORD WINAPI Summation(LPVOID Param) { DWORD UPPER = *(DWORD*) Param; for (DWORD I = 0; I <= Upper; i++) Sum += I; return 0; } int main (int argc, char *argv[]) { DWORD ThreadId; HANDLE ThreadHandle; int Param; if (argc !=2){ fprintf(stderr,”An integer parameter is required\n”); return – 1; } Param=atoi(argv[1]); if (Param<0){ fprintf(stderr,”An integer >= 0 is required\n); return – 1; }
ThreadHandle=CreateThread( NULL, 0, Summation, &Param, 0, &ThreadId); if (ThreadHandle != NULL){ WaitForSingleObject(ThreadHandle, INFINITE); CloseHandle(ThreadHandle); printf(“sum = %d\n”,Sum); } }
4.3.3 JAVA THREADS Threads are fundamental model of program execution in a Java program, and the Java language and it’s API provide a rich set of features for the creation and management of threads.
class Sum { private int sum; public int getSum() { return sum; } public void setSum (int sum) { this.sum = sum; } } class Summation implements Runnable { private int upper; private Sum sumValue; public Summation (int upper, Sum sumValue) { this.upper = upper; this.sumValue = sumValue } public void run() { int sum = 0; for (int i=0; i<= upper; i++) sum+=I; sumValue.setSum(sum); } }
public class Driver { public static void main(String[]args){ if(args.length >0){ if (Integer.parseInt (args[0])<0) System.err.printIn(args[0]+” must be >= 0.”); else{ Sum sumObject = new Sum(); int upper = Integer.parseInt(args[0]); Thread thrd = new Thread(new Summation (upper, sumObject)); thrd.start(); try { thrd.join(); System.out.printIn (“The sum of “+upper+” is “+sumObject.getSum()); } catch (InterruptedException ie) { } } } else System.err.println(“Usage: Summation <integer value>”); } }
4.4.3 THREADING ISSUES In this section, we discuss some of the issues to consider with multithreaded programs.
4.4.2 CANCELLATION Thread cancellation  –  is the task of terminating a thread before it has completed. Example:  if multiple threads are concurrently searching through a database and one thread returns the result, the remaining threads might be canceled .
Cancellation points –  Pthreads refers to such as cancellation points. 4.4.3 SIGNAL HANDLING Signal  – used in UNIX systems to notify  a process that a particular event has occurred.
All signals, whether synchronous or asynchronous , follow the same pattern: A signal is generated by the occurrence of a particular event. A generated signal is delivered to a process. One delivered, the signal must be handled.
Signal Asynchronously  – when a signal is generated by an event external to a running process. Example: include terminating process with specific  Keystrokes  ( such as <control> <C> ) and have a timer expire. Every signal may be handled by one of two possible handlers: 1. A default signal handler 2. A user-defined signal handler
Default Signal Handler  – run by  the kernel when handling that signal. User-defined signal handler  – that is called to handle the signal. Asynchronous procedure calls (APCs)  – the Windows can be emulated using this.
4.4.4 THREAD POOLS Limits the number of threads that exist at anyone point. This is particularly important on systems that cannot support a large number of concurrent threads. Example: DWORD WINAPI PoolFunction (AVOID Param) { /** * this function runs as a separate thread. **/ }
QueueUserWorkItem ( ) function , which is passed three parameters: LPTHREAD_START_ROUTINE Function – a pointer to the function that is to run as a separate thread. PVOID Param – the parameters passed to Function. ULONG Flags – flags indicating how the thread pool is to create and manage execution of the thread.
4.4.5 THREAD-SPECIFIC DATA In a transaction-processing system, we might service each transaction in a separate thread. User thread Lightweight  process Kernel thread Figure 4.9  Lightweight process (LWP) LWP  k
4.4.6 SCHEDULAR ACTIVATIONS One scheme for communication between the user-thread library and the kernel is known as  schedular activation .  upcall –  the kernel must inform an application about certain events. upcall handler  – upcalls are handled by the thread libarary and it must run on a virtual processor.
4.5 OPERATING SYSTEM EXAMPLES 4.5.1 WINDOW XP THREADS it implements the WIN32 API. The WIN32 API is the primary API for the family of Microsoft O.S.  The general components  of a thread include: A thread ID unquely identifying the thread A register set representing the status of the processor.
A user stack, employed when the thread is running in user mode, and a kernel stack, employed when the thread is running in kernel mode A private storage area used by various run-time libraries and dynamic link libraries (DLLs)
The register set, stacks, and private storage area are known as the context of a thread include: ETHREAD – executive thread block KTHREAD – kernel thread block TEB – thread environment block
4.5.2 Linux Threads Lynux  provides the fork ( ) system call it also provides the ability to create threads using the clone( ) system call uses the distinguish between processes and threads. Uses the term  task   – rather process or thread.
Some of these flags are listed below: The set of open file is shared.  CLONE_FILES Signal handlers are shared. CLONE_SIGHAND The same memory space is shared. CLONE_VM File-system information is shared. CLONE_FS MEANING FLAG
SUMMARY THREAD  – is a flow  of control within a process. MULTITHREADED PROCESS  – contains several different flows of control within the same address space. It includes increased responsiveness to the user, resource sharing within process, economy, and the ability to take advantage of multiprocessor architecture.
USER-LEVEL THREADS  – are threads that are visible to the programmer and are unknown to the kernel. THREE DIFFERENT TYPES OF MODELS RELATE USER AND KERNEL THREADS: 1. many to one model maps 2. one-to-one model maps 3. many-to-many model maps
THE END…

More Related Content

PPTX
Threads .ppt
meet darji
 
PPTX
Multithreading models.ppt
Luis Goldster
 
PPTX
Architecture of operating system
Supriya Kumari
 
PPTX
File Management in Operating System
Janki Shah
 
PDF
Distributed Operating System_4
Dr Sandeep Kumar Poonia
 
PPT
Cluster Computing
BOSS Webtech
 
PPTX
Presentation on Segmentation
Priyanka bisht
 
PPTX
Message and Stream Oriented Communication
Dilum Bandara
 
Threads .ppt
meet darji
 
Multithreading models.ppt
Luis Goldster
 
Architecture of operating system
Supriya Kumari
 
File Management in Operating System
Janki Shah
 
Distributed Operating System_4
Dr Sandeep Kumar Poonia
 
Cluster Computing
BOSS Webtech
 
Presentation on Segmentation
Priyanka bisht
 
Message and Stream Oriented Communication
Dilum Bandara
 

What's hot (20)

PDF
Java threads
Prabhakaran V M
 
PPT
Clock synchronization in distributed system
Sunita Sahu
 
PDF
Dbms 14: Relational Calculus
Amiya9439793168
 
PPT
Real-Time Scheduling
sathish sak
 
PPTX
Front end web development
viveksewa
 
PPTX
Virtualization
Srisailam Reddy Kanapuram
 
PDF
Design issues of dos
vanamali_vanu
 
PPTX
Linux booting Process
Gaurav Sharma
 
PPTX
Multithreading in java
Monika Mishra
 
PDF
Lecture 1 introduction to parallel and distributed computing
Vajira Thambawita
 
PDF
Memory management
Rajni Sirohi
 
PPTX
Packages in java
Elizabeth alexander
 
PPTX
Linux process management
Raghu nath
 
PDF
Thread
Mohd Arif
 
PPTX
Process management os concept
priyadeosarkar91
 
PPTX
Amoeba distributed operating System
Saurabh Gupta
 
PPT
Operating Systems - "Chapter 4: Multithreaded Programming"
Ra'Fat Al-Msie'deen
 
PPTX
Cloud sim
Khyati Rajput
 
PPTX
Java package
CS_GDRCST
 
PDF
operating system structure
Waseem Ud Din Farooqui
 
Java threads
Prabhakaran V M
 
Clock synchronization in distributed system
Sunita Sahu
 
Dbms 14: Relational Calculus
Amiya9439793168
 
Real-Time Scheduling
sathish sak
 
Front end web development
viveksewa
 
Design issues of dos
vanamali_vanu
 
Linux booting Process
Gaurav Sharma
 
Multithreading in java
Monika Mishra
 
Lecture 1 introduction to parallel and distributed computing
Vajira Thambawita
 
Memory management
Rajni Sirohi
 
Packages in java
Elizabeth alexander
 
Linux process management
Raghu nath
 
Thread
Mohd Arif
 
Process management os concept
priyadeosarkar91
 
Amoeba distributed operating System
Saurabh Gupta
 
Operating Systems - "Chapter 4: Multithreaded Programming"
Ra'Fat Al-Msie'deen
 
Cloud sim
Khyati Rajput
 
Java package
CS_GDRCST
 
operating system structure
Waseem Ud Din Farooqui
 
Ad

Similar to Operating System Chapter 4 Multithreaded programming (20)

PPT
Threads in Operating systems and concepts
RamaSubramanian79
 
PDF
Threads operating system slides easy understand
shamsulhuda34
 
PPTX
OS Module-2.pptx
bleh23
 
PDF
CH04.pdf
ImranKhan880955
 
PPTX
Threads
Dr. SURBHI SAROHA
 
PPTX
Os
DeepaR42
 
PDF
Sucet os module_2_notes
SRINIVASUNIVERSITYEN
 
PPTX
process and thread.pptx
HamzaxTv
 
PPTX
P-Threads
Bharathwaj_v
 
PPT
Operating System 4
tech2click
 
PPT
Operating System 4 1193308760782240 2
mona_hakmy
 
PDF
Multithreaded Programming in oprating system
YOGENDRAMS
 
PPT
Chapter 6 os
AbDul ThaYyal
 
PDF
threads (1).pdfmjlkjfwjgliwiufuaiusyroayr
abhinandpk2405
 
PPT
Multithreading
backdoor
 
PPT
Intro To .Net Threads
rchakra
 
PPTX
Topic 4- processes.pptx
DanishMahmood23
 
PPTX
WEEK07operatingsystemdepartmentofsoftwareengineering.pptx
babayaga920391
 
PPT
Introto netthreads-090906214344-phpapp01
Aravindharamanan S
 
PPT
Posix threads(asha)
Nagarajan
 
Threads in Operating systems and concepts
RamaSubramanian79
 
Threads operating system slides easy understand
shamsulhuda34
 
OS Module-2.pptx
bleh23
 
CH04.pdf
ImranKhan880955
 
Sucet os module_2_notes
SRINIVASUNIVERSITYEN
 
process and thread.pptx
HamzaxTv
 
P-Threads
Bharathwaj_v
 
Operating System 4
tech2click
 
Operating System 4 1193308760782240 2
mona_hakmy
 
Multithreaded Programming in oprating system
YOGENDRAMS
 
Chapter 6 os
AbDul ThaYyal
 
threads (1).pdfmjlkjfwjgliwiufuaiusyroayr
abhinandpk2405
 
Multithreading
backdoor
 
Intro To .Net Threads
rchakra
 
Topic 4- processes.pptx
DanishMahmood23
 
WEEK07operatingsystemdepartmentofsoftwareengineering.pptx
babayaga920391
 
Introto netthreads-090906214344-phpapp01
Aravindharamanan S
 
Posix threads(asha)
Nagarajan
 
Ad

Recently uploaded (20)

PPTX
Software Engineering BSC DS UNIT 1 .pptx
Dr. Pallawi Bulakh
 
PDF
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
PPTX
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
DOCX
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PDF
Types of Literary Text: Poetry and Prose
kaelandreabibit
 
PPTX
Measures_of_location_-_Averages_and__percentiles_by_DR SURYA K.pptx
Surya Ganesh
 
PPTX
Understanding operators in c language.pptx
auteharshil95
 
PDF
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
PPTX
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
PPTX
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
PDF
Arihant Class 10 All in One Maths full pdf
sajal kumar
 
PPTX
vedic maths in python:unleasing ancient wisdom with modern code
mistrymuskan14
 
PDF
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
PPTX
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
PPTX
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 
PDF
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
Sandeep Swamy
 
PDF
Exploring-Forces 5.pdf/8th science curiosity/by sandeep swamy notes/ppt
Sandeep Swamy
 
PDF
5.EXPLORING-FORCES-Detailed-Notes.pdf/8TH CLASS SCIENCE CURIOSITY
Sandeep Swamy
 
Software Engineering BSC DS UNIT 1 .pptx
Dr. Pallawi Bulakh
 
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
Types of Literary Text: Poetry and Prose
kaelandreabibit
 
Measures_of_location_-_Averages_and__percentiles_by_DR SURYA K.pptx
Surya Ganesh
 
Understanding operators in c language.pptx
auteharshil95
 
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
Arihant Class 10 All in One Maths full pdf
sajal kumar
 
vedic maths in python:unleasing ancient wisdom with modern code
mistrymuskan14
 
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
Sandeep Swamy
 
Exploring-Forces 5.pdf/8th science curiosity/by sandeep swamy notes/ppt
Sandeep Swamy
 
5.EXPLORING-FORCES-Detailed-Notes.pdf/8TH CLASS SCIENCE CURIOSITY
Sandeep Swamy
 

Operating System Chapter 4 Multithreaded programming

  • 1. MULTI-THREADED PROGRAMMING Reported by: N ikko D elumen M ary J oy T apar
  • 2. 4.1 OVERVIEW Thread – basic unit of CPU utilization; it comprises a thread ID, a program counter, a register set, and a stack.
  • 3. 4.1.1 MOTIVATION Many software packages that run on modern desktop PCs are multithreaded. Example: A word processor may have a thread for displaying graphics, another for responding to keystrokes, and a third is for performing spelling and grammar checking in background.
  • 4. thread thread Single-threaded process Multi-threaded process
  • 5. Recall from CHAPTER3 “ RPCs allow interprocess communication by providing a communication mechanism similar to ordinary function or procedure calls.” Typically, RPC servers are multithreaded. When server receives a message, it services the message using a separate thread.
  • 6. 4.1.2 BENEFITS Responsiveness. Multithreading an interactive application may allow a program to continue running even if part of it is blocked or is performing a lengthy operation, thereby increasing responsiveness to the user.
  • 7. Resource Sharing. By default, threads share the memory and the resources of the process to which they belong. Economy. Allocating memory and resources for process creation is costly. Because threads share resources of the process to which they belong, it is more economical to create and context-switch threads.
  • 8. Utilization of multiprocessor architectures. Threads may be running in parallel on different processors. A single-threaded process can only run on one CPU, no matter how many are available.
  • 9. 4.2 MULTI-THREADING MODELS Support for threads may be provided either at the user level, for user threads, or by the kernel, for kernel threads.
  • 10. 4.2.1 Many-to-One Model User thread Kernel thread
  • 11. 4.2.2 One-to-One Model User thread Kernel thread
  • 12. Two-level Model User thread Kernel thread
  • 13. 4.2.3 Many-to-Many Model User thread Kernel thread
  • 14. 4.3 THREAD LIBRARIES A Thread Library provides the programmer an API for creating and managing threads.
  • 15. Two Primary Ways of Implementing a Thread Library To provide a library entirely in user with no kernel support. All code and data structures for the library exist in user space. To implement a kernel-level library supported directly by the operating system. Code and data structures for the library exist in kernel space.
  • 16. 4.3.1 PTHREADS Pthreads refers to the POSIX standard (IEEE 1003.1c) defining an API for thread creation and synchronization.
  • 17. #include <pthread.h> #include <stdio.h> int sum; void *runner(void *param); int main(int argc, char *argv[]) { pthread.t tid; pthread_attr_t attr; if (argc !=2){ fprintf(stderr,”usage: a.out(integer value>\n”); return -1; } if (atoi (argv[1]) < 0) { fprintf(stderr,”%d must be >= 0\n”, atoi (argv[1])); return -1; } pthread_attr_init(&attr); pthread_create (&tid, &attr, runner, argv[1]); pthread_join (tid,NULL); printf(“sum=%d\n”, sum); } void *runner(void *param) { int i, upper = atoi(param) sum = 0; for (i=1; i<=upper; i++) sum += I; pthread_exit (0); }
  • 18. 4.3.2 WIN32 THREADS The technique of creating threads using Win32 thread library is similar to the Pthreads technique in several ways.
  • 19. #include <windows.h> #include <stdio.h> DWORD Sum; DWORD WINAPI Summation(LPVOID Param) { DWORD UPPER = *(DWORD*) Param; for (DWORD I = 0; I <= Upper; i++) Sum += I; return 0; } int main (int argc, char *argv[]) { DWORD ThreadId; HANDLE ThreadHandle; int Param; if (argc !=2){ fprintf(stderr,”An integer parameter is required\n”); return – 1; } Param=atoi(argv[1]); if (Param<0){ fprintf(stderr,”An integer >= 0 is required\n); return – 1; }
  • 20. ThreadHandle=CreateThread( NULL, 0, Summation, &Param, 0, &ThreadId); if (ThreadHandle != NULL){ WaitForSingleObject(ThreadHandle, INFINITE); CloseHandle(ThreadHandle); printf(“sum = %d\n”,Sum); } }
  • 21. 4.3.3 JAVA THREADS Threads are fundamental model of program execution in a Java program, and the Java language and it’s API provide a rich set of features for the creation and management of threads.
  • 22. class Sum { private int sum; public int getSum() { return sum; } public void setSum (int sum) { this.sum = sum; } } class Summation implements Runnable { private int upper; private Sum sumValue; public Summation (int upper, Sum sumValue) { this.upper = upper; this.sumValue = sumValue } public void run() { int sum = 0; for (int i=0; i<= upper; i++) sum+=I; sumValue.setSum(sum); } }
  • 23. public class Driver { public static void main(String[]args){ if(args.length >0){ if (Integer.parseInt (args[0])<0) System.err.printIn(args[0]+” must be >= 0.”); else{ Sum sumObject = new Sum(); int upper = Integer.parseInt(args[0]); Thread thrd = new Thread(new Summation (upper, sumObject)); thrd.start(); try { thrd.join(); System.out.printIn (“The sum of “+upper+” is “+sumObject.getSum()); } catch (InterruptedException ie) { } } } else System.err.println(“Usage: Summation <integer value>”); } }
  • 24. 4.4.3 THREADING ISSUES In this section, we discuss some of the issues to consider with multithreaded programs.
  • 25. 4.4.2 CANCELLATION Thread cancellation – is the task of terminating a thread before it has completed. Example: if multiple threads are concurrently searching through a database and one thread returns the result, the remaining threads might be canceled .
  • 26. Cancellation points – Pthreads refers to such as cancellation points. 4.4.3 SIGNAL HANDLING Signal – used in UNIX systems to notify a process that a particular event has occurred.
  • 27. All signals, whether synchronous or asynchronous , follow the same pattern: A signal is generated by the occurrence of a particular event. A generated signal is delivered to a process. One delivered, the signal must be handled.
  • 28. Signal Asynchronously – when a signal is generated by an event external to a running process. Example: include terminating process with specific Keystrokes ( such as <control> <C> ) and have a timer expire. Every signal may be handled by one of two possible handlers: 1. A default signal handler 2. A user-defined signal handler
  • 29. Default Signal Handler – run by the kernel when handling that signal. User-defined signal handler – that is called to handle the signal. Asynchronous procedure calls (APCs) – the Windows can be emulated using this.
  • 30. 4.4.4 THREAD POOLS Limits the number of threads that exist at anyone point. This is particularly important on systems that cannot support a large number of concurrent threads. Example: DWORD WINAPI PoolFunction (AVOID Param) { /** * this function runs as a separate thread. **/ }
  • 31. QueueUserWorkItem ( ) function , which is passed three parameters: LPTHREAD_START_ROUTINE Function – a pointer to the function that is to run as a separate thread. PVOID Param – the parameters passed to Function. ULONG Flags – flags indicating how the thread pool is to create and manage execution of the thread.
  • 32. 4.4.5 THREAD-SPECIFIC DATA In a transaction-processing system, we might service each transaction in a separate thread. User thread Lightweight process Kernel thread Figure 4.9 Lightweight process (LWP) LWP k
  • 33. 4.4.6 SCHEDULAR ACTIVATIONS One scheme for communication between the user-thread library and the kernel is known as schedular activation . upcall – the kernel must inform an application about certain events. upcall handler – upcalls are handled by the thread libarary and it must run on a virtual processor.
  • 34. 4.5 OPERATING SYSTEM EXAMPLES 4.5.1 WINDOW XP THREADS it implements the WIN32 API. The WIN32 API is the primary API for the family of Microsoft O.S. The general components of a thread include: A thread ID unquely identifying the thread A register set representing the status of the processor.
  • 35. A user stack, employed when the thread is running in user mode, and a kernel stack, employed when the thread is running in kernel mode A private storage area used by various run-time libraries and dynamic link libraries (DLLs)
  • 36. The register set, stacks, and private storage area are known as the context of a thread include: ETHREAD – executive thread block KTHREAD – kernel thread block TEB – thread environment block
  • 37. 4.5.2 Linux Threads Lynux provides the fork ( ) system call it also provides the ability to create threads using the clone( ) system call uses the distinguish between processes and threads. Uses the term task – rather process or thread.
  • 38. Some of these flags are listed below: The set of open file is shared. CLONE_FILES Signal handlers are shared. CLONE_SIGHAND The same memory space is shared. CLONE_VM File-system information is shared. CLONE_FS MEANING FLAG
  • 39. SUMMARY THREAD – is a flow of control within a process. MULTITHREADED PROCESS – contains several different flows of control within the same address space. It includes increased responsiveness to the user, resource sharing within process, economy, and the ability to take advantage of multiprocessor architecture.
  • 40. USER-LEVEL THREADS – are threads that are visible to the programmer and are unknown to the kernel. THREE DIFFERENT TYPES OF MODELS RELATE USER AND KERNEL THREADS: 1. many to one model maps 2. one-to-one model maps 3. many-to-many model maps