Professional Documents
Culture Documents
Bil302 Hafta4
Bil302 Hafta4
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
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
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ı
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)
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
Operating System Concepts with Java – 8th Edition 14.21 Silberschatz, Galvin and Gagne ©2009
Pthreads
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
Operating System Concepts with Java – 8th Edition 14.30 Silberschatz, Galvin and Gagne ©2009
İş Parçacığı İptali
Operating System Concepts with Java – 8th Edition 14.32 Silberschatz, Galvin and Gagne ©2009
İş Parçacığı Havuzları
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