bölüm 4: İş parçacıkları · bölüm 4: İş parçacıkları genel bakış Çoklu İş...
TRANSCRIPT
14.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8th Edition
Bölüm 4: İş Parçacıkları
14.2 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8th Edition
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
14.3 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8th Edition
Hedefler
Pthreads, Win32, ve Java iş parçacığı kütüphanelerinin tanıtımı
Çok iş parçacıklı programlamada ortaya çıkan meselelerin irdelenmesi
İş parçacığı kavramını tanıtmak
14.4 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8th Edition
Tek ve Çok İş Parçacıklı İşlemler
14.5 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8th Edition
Faydalar
Cevap Verebilirlik (Responsiveness)
Kaynak Paylaşımı (Resource Sharing)
Ekonomi (Economy)
Ölçeklenebilirlik (Scalability)
14.7 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8th Edition
Çok İş Parçacıklı Sunucu Mimarisi
14.10 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8th Edition
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ı
14.11 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8th Edition
Çekirdek İş Parçacıkları
Örnekler
Windows XP/2000
Linux
Mac OS X
Çekirdek tarafından yönetilir, Kullanıcı modu ile kernel modu geçişleri maliyetlidir.
14.12 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8th Edition
Çoklu İş Parçacığı Modelleri
Çoktan-Teke (Many-to-One)
Teke-Tek (One-to-One)
Çoktan-Çoka (Many-to-Many)
14.13 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8th Edition
Ç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.
14.15 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8th Edition
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ı
14.17 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8th Edition
Ç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
14.21 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8th Edition
İş 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
14.22 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8th Edition
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)
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.)
14.30 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8th Edition
İş Parçacıkları ile İlgili Mevzular
Hedef iş parçacığının iptali
Asenkron veya ertelenen
İş parçacığı havuzları
14.32 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8th Edition
İş 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
14.34 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8th Edition
İş 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