Top Banner
Pertemuan 13 Threads Matakuliah : H0483 / Network Programming Tahun : 2005 Versi : 1.0
20

Pertemuan 13 Threads Matakuliah: H0483 / Network Programming Tahun: 2005 Versi: 1.0.

Dec 14, 2015

Download

Documents

Alexa Ferrand
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Pertemuan 13 Threads Matakuliah: H0483 / Network Programming Tahun: 2005 Versi: 1.0.

Pertemuan 13Threads

Matakuliah : H0483 / Network Programming

Tahun : 2005

Versi : 1.0

Page 2: Pertemuan 13 Threads Matakuliah: H0483 / Network Programming Tahun: 2005 Versi: 1.0.

Learning Outcomes

Pada akhir pertemuan ini, diharapkan mahasiswa

akan mampu :

• menghasilkan program dengan menggunakan Threads

Page 3: Pertemuan 13 Threads Matakuliah: H0483 / Network Programming Tahun: 2005 Versi: 1.0.

Outline Materi

• Introduction

• Basic threads function

• TCP echo using threads

Page 4: Pertemuan 13 Threads Matakuliah: H0483 / Network Programming Tahun: 2005 Versi: 1.0.

Threads

Processes and Threads

• Pengertian Proses• Pengertian Threads• Interprocess communication pada Threads

Page 5: Pertemuan 13 Threads Matakuliah: H0483 / Network Programming Tahun: 2005 Versi: 1.0.

ProcessesThe Process Model

• Multiprogramming of four programs• Conceptual model of 4 independent, sequential processes• Only one program active at any instant

Page 6: Pertemuan 13 Threads Matakuliah: H0483 / Network Programming Tahun: 2005 Versi: 1.0.

Process Creation

Principal events that cause process creation

1. System initialization

2. Execution of a process creation system

3. User request to create a new process

4. Initiation of a batch job

Page 7: Pertemuan 13 Threads Matakuliah: H0483 / Network Programming Tahun: 2005 Versi: 1.0.

Process Termination

Conditions which terminate processes

1. Normal exit (voluntary)

2. Error exit (voluntary)

3. Fatal error (involuntary)

4. Killed by another process (involuntary)

Page 8: Pertemuan 13 Threads Matakuliah: H0483 / Network Programming Tahun: 2005 Versi: 1.0.

Process Hierarchies

• Parent creates a child process, child processes can create its own process

• Forms a hierarchy– UNIX calls this a "process group"

• Windows has no concept of process hierarchy– all processes are created equal

Page 9: Pertemuan 13 Threads Matakuliah: H0483 / Network Programming Tahun: 2005 Versi: 1.0.

Process States (1)

• Possible process states– running– blocked– ready

• Transitions between states shown

Page 10: Pertemuan 13 Threads Matakuliah: H0483 / Network Programming Tahun: 2005 Versi: 1.0.

ThreadsThe Thread Model (1)

(a) Three processes each with one thread(b) One process with three threads

Page 11: Pertemuan 13 Threads Matakuliah: H0483 / Network Programming Tahun: 2005 Versi: 1.0.

The Thread Model (2)

• Items shared by all threads in a process

• Items private to each thread

Page 12: Pertemuan 13 Threads Matakuliah: H0483 / Network Programming Tahun: 2005 Versi: 1.0.

The Thread Model (3)

Each thread has its own stack

Page 13: Pertemuan 13 Threads Matakuliah: H0483 / Network Programming Tahun: 2005 Versi: 1.0.

Thread Usage (1)

A word processor with three threads

Page 14: Pertemuan 13 Threads Matakuliah: H0483 / Network Programming Tahun: 2005 Versi: 1.0.

Thread Usage (2)

A multithreaded Web server

Page 15: Pertemuan 13 Threads Matakuliah: H0483 / Network Programming Tahun: 2005 Versi: 1.0.

Thread Usage (3)

• Rough outline of code for previous slide(a) Dispatcher thread(b) Worker thread

Page 16: Pertemuan 13 Threads Matakuliah: H0483 / Network Programming Tahun: 2005 Versi: 1.0.

Thread Usage (4)

Three ways to construct a server

Page 17: Pertemuan 13 Threads Matakuliah: H0483 / Network Programming Tahun: 2005 Versi: 1.0.

Pop-Up Threads

• Creation of a new thread when message arrives(a) before message arrives(b) after message arrives

Page 18: Pertemuan 13 Threads Matakuliah: H0483 / Network Programming Tahun: 2005 Versi: 1.0.

Making Single-Threaded Code Multithreaded (1)

Conflicts between threads over the use of a global variable

Page 19: Pertemuan 13 Threads Matakuliah: H0483 / Network Programming Tahun: 2005 Versi: 1.0.

Making Single-Threaded Code Multithreaded (2)

Threads can have private global variables

Page 20: Pertemuan 13 Threads Matakuliah: H0483 / Network Programming Tahun: 2005 Versi: 1.0.

<< CLOSING>>

• Tugas :– Buat Program Daytimeserver dengan

menggunakan Threads