You are on page 1of 25

Bölüm 4: İş Parçacıkları

Operating System Concepts with Java – 8th Edition 14.1 Silberschatz, Galvin and Gagne ©2009
Bölüm 4: İş Parçacıkları

 Genel Bakış
 Çoklu İş Parçacığı Modelleri
 İş Parçacığı Kütüphaneleri
 İş Parçacıkları ile İlgili Meseleler
 İşletim Sistemi Örnekleri

Operating System Concepts with Java – 8th Edition 14.2 Silberschatz, Galvin and Gagne ©2009
Hedefler

 İş parçacığı kavramını tanıtmak

 Pthreads, Win32, ve Java iş parçacığı kütüphanelerinin tanıtımı

 Çok iş parçacıklı programlamada ortaya çıkan meselelerin irdelenmesi

Operating System Concepts with Java – 8th Edition 14.3 Silberschatz, Galvin and Gagne ©2009
Tek ve Çok İş Parçacıklı İşlemler

Operating System Concepts with Java – 8th Edition 14.4 Silberschatz, Galvin and Gagne ©2009
Faydalar

 Cevap Verebilirlik (Responsiveness)

 Kaynak Paylaşımı (Resource Sharing)

 Ekonomi (Economy)

 Ölçeklenebilirlik (Scalability)

Operating System Concepts with Java – 8th Edition 14.5 Silberschatz, Galvin and Gagne ©2009
Çok İş Parçacıklı Sunucu Mimarisi

Operating System Concepts with Java – 8th Edition 14.7 Silberschatz, Galvin and Gagne ©2009
Kullanıcı İş Parçacıkları

 İş parçacığı yönetimi kullanıcı seviyesinde tanımlı iş parçacığı


kütüphaneleri ile sağlanır

 Üç ana iş parçacığı kütüphanesi:


 POSIX Pthreads
 Win32 iş parçacıkları
 Java iş parçacıkları

Operating System Concepts with Java – 8th Edition 14.10 Silberschatz, Galvin and Gagne ©2009
Çekirdek İş Parçacıkları
 Çekirdek tarafından yönetilir, Kullanıcı modu ile kernel modu geçişleri
maliyetlidir.
 Örnekler
 Windows XP/2000
 Linux
 Mac OS X

Operating System Concepts with Java – 8th Edition 14.11 Silberschatz, Galvin and Gagne ©2009
Çoklu İş Parçacığı Modelleri

 Çoktan-Teke (Many-to-One)

 Teke-Tek (One-to-One)

 Çoktan-Çoka (Many-to-Many)

Operating System Concepts with Java – 8th Edition 14.12 Silberschatz, Galvin and Gagne ©2009
Çoktan-Teke (Many-to-One)

 Pek çok kullanıcı seviyesindeki iş parçacığı tek bir çekirdek iş parçacığı


ile eşleşir
 Çoklu işlemcikleri desteklemeyen
çekirdeklerde kullanılır.

Operating System Concepts with Java – 8th Edition 14.13 Silberschatz, Galvin and Gagne ©2009
Teke-Tek (One-to-One)

 Her bir kullanıcı seviyesi iş parçacığı tek bir çekirdek iş parçacığı ile
eşleşir

 Örnekler
 Windows NT/XP/2000
 Linux
 Solaris 9 ve sonrası

Operating System Concepts with Java – 8th Edition 14.15 Silberschatz, Galvin and Gagne ©2009
Çoktan-Çoka (Many-to-Many)
 Pek çok kullanıcı seviyesi iş parçacığı pek çok çekirdek iş parçacığı
ile eşleşir
 İşletim sisteminin yeterince çekirdek iş parçacığı oluşturmasını
sağlar
 ThreadFiber paketi ile Windows NT/2000

Operating System Concepts with Java – 8th Edition 14.17 Silberschatz, Galvin and Gagne ©2009
İş Parçacığı Kütüphaneleri

 İş parçacığı kütüphanesi programcıya iş parçacıklarının


oluşturulmasını ve yönetilmesini sağlayan bir API sunar

 Gerçekleştirim için iki temel yol


 Kütüphane tamamen kullanıcı alanında
 İşletim sistemi tarafından desteklenen çekirdek seviyesinde
kütüphane

Operating System Concepts with Java – 8th Edition 14.21 Silberschatz, Galvin and Gagne ©2009
Pthreads

 Kullanıcı seviyesinde veya çekirdek seviyesinde sunulabilir

 İş parçacığı oluşturmak ve iş parçacıklarının senkronizasyonunu


sağlamak için bir POSIX standardı (IEEE 1003.1c)
 UNIX işletim sistemlerinde genel olarak kullanılıyor (Solaris, Linux,
Mac OS X)

Operating System Concepts with Java – 8th Edition 14.22 Silberschatz, Galvin and Gagne ©2009
Pthreads Example
 All Pthreads programs must include the pthread.h
header file.
 The statement pthread_t tid declares the identifier
for the thread we will create.
 Each thread has a set of attributes, including stack size
and scheduling information.
 A separate thread is created with the
pthread_create() function call.
Pthreads Example
 the program has two threads:
 the initial (or parent) thread in main()
 and the summation (or child) thread performing the
summation operation in the runner() function.
 This program follows the fork-join strategy described
earlier: after creating the summation thread, the parent
thread will wait for it to terminate by calling the pthread
join() function.
 The summation thread will terminate when it calls the
function pthread exit().
 Once the summation thread has returned, the parent
thread will output the value of the shared data sum.
Pthreads Example
Pthreads Example (Cont.)
Windows threads
 The technique for creating threads using the Windows
thread library is similar to the Pthreads technique in
several ways.
 Threads are created in the Windows API using the
CreateThread() function, a set of attributes for the thread
is passed to this function.
 We illustrate the Windows thread API in the C program.
 Notice that we must include the windows.h header file
when using the Windows API.
 NOTE: the DWORD data type is an unsigned 32-bit
integer
Windows threads
 Recall that the POSIX Pthread program had the parent
thread wait for the summation thread using the pthread
join() statement.
 We perform the equivalent of this in the Windows API
using the WaitForSingleObject() function, which causes
the creating thread to block until the summation thread
has exited.
 In situations that require waiting for multiple threads to
complete, the WaitForMultipleObjects() function is used.
Win32 threads Example
Win32 API Multithreaded C Program (Cont.)
İş Parçacıkları ile İlgili Mevzular

 Hedef iş parçacığının iptali


 Asenkron veya ertelenen
 İş parçacığı havuzları

Operating System Concepts with Java – 8th Edition 14.30 Silberschatz, Galvin and Gagne ©2009
İş Parçacığı İptali

 Bir iş parçacığının işi bitmeden sonlandırılması

 İki genel yaklaşım:


 Asenkron iptal hedef iş parçacığını anında iptal eder
 Ertelenen iptal hedef iş parçacığının düzenli olarak iptal
edilmesi gerekip gerkmediğini kontrol etmesini sağlar

Operating System Concepts with Java – 8th Edition 14.32 Silberschatz, Galvin and Gagne ©2009
İş Parçacığı Havuzları

 Bir havuzda, kendilerine atanacak işleri beklemek üzere belli sayıda iş


parçacığı oluştur

 Avantajlar:
 Genellikle varolan bir iş parçacığı ile bir isteği gerçekleştirmek,
yeni bir iş parçacığı oluşturarak gerçekleştirmekten biraz daha
hızlı
 Uygulamalardaki iş parçacıklarının sayısı iş parçacığı havuzunun
boyutu ile sınırlandırılır

Operating System Concepts with Java – 8th Edition 14.34 Silberschatz, Galvin and Gagne ©2009

You might also like