Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 4 Multithreading programming

Similar presentations


Presentation on theme: "Chapter 4 Multithreading programming"— Presentation transcript:

1 Chapter 4 Multithreading programming
Dr. Arwa Zabian

2 Multithreading Thread is the basic unit of CPU utilization, it comprises: thread ID, program counter, register set and stack It shares by other threads in the same process (code section. Data section , and OS resources) Multithreading process it can performs more than one task at time.

3 Example of multithreading
Downloading web page : one thread can display the text, another display the image and third thread retrieve data from the server Web server can serve more than one client at time , each client is thread If the web server is single threading , it must respond to one client at time Remote call procedure for inter-process communication is multithreading Most of the operating system is multithreading , each thread performs a specific task.

4 Benefits Responsiveness : is an interactive application that allows a program to continue running even if part of it is blocked or it performs long operation Resource sharing : multithreads share code and data ( memory and resources of the process to which they belong by default )……saving in memory space. Economy Scalability : multithread can run in parallel and can execute more jobs

5 Multicores programming
Multicore in one chip , each core is appears to the OS as a process Example : an application with 4 threads One core multicore core 1 core 2 T1 T4 T3 T2 T3 T1 T4 T2 scheduling

6 Problems with multicore programming
Divide activities: examining the application to find in which part can run concurrently and in parallel Balance : after identifying the tasks that run concurrently, the programmers must divide it into different tasks that perform equal work and equal value. Data splitting : the data accessed and manipulated must be divided to run on separate core Data dependency : some tasks are dependent for that running such tasks in parallel requires synchronization. testing and debugging : when threads running in parallel, there are many paths for that debugging is more difficult.

7 Multithreading models
multithreading model represent s the relation between user model and kernel model One to one model: Each thread is mapped to one kernel thread in parallel, each user thread is running separately Drawback : overhead in creating many kernek threads.

8 Many to one Many user –level thread are mapped to one kernel thread , multithreads running in parallel but only one thread can access the kernel at time If one thread male a blocking system call al the processes will be blocked Multi-clients send on one channel, if one client make block sending , the channel status will be block sending and no one send on the channel.

9 Many to many model The number of user threads > the number of kernel thread The kernel can schedule only one thread at time When a user thread performs a blocking system call the kernel schedule another thread for execution. Can be considered as two level the first level is multithreading . And the second level can be one to one model


Download ppt "Chapter 4 Multithreading programming"

Similar presentations


Ads by Google