Professional Documents
Culture Documents
Overview
Multicore Programming
Multithreading Models
Thread Libraries
Threading Issues
Operating System Examples
Objectives
To introduce the notion of a threada fundamental unit of CPU
Linux
Motivation
Most modern applications are multithreaded
Threads run within application
Multiple tasks with the application can be implemented by
separate threads
Update display
Fetch data
Spell checking
weight
Thread Benefits
Responsiveness may allow continued execution if part of
architectures
Multicore Programming
Multicore or multiprocessor systems putting pressure on
Dividing activities
Balance
Data splitting
Data dependency
Every thing done in time sliced manner where the time sliced is as
miniumum that can be predicted so easily.
POSIX Pthreads
Windows threads
Java threads
Windows
Solaris
Linux
Tru64 UNIX
Mac OS X
Multithreading Models
Many-to-One
One-to-One
Many-to-Many
Many-to-One
Many user-level threads mapped to
One-to-One
Each user-level thread maps to kernel thread
Creating a user-level thread creates a kernel thread
More concurrency than many-to-one
Number of threads per process sometimes
Examples
Windows
Linux
Many-to-Many Model
Allows many user level threads to be
package
Two-level Model
Similar to M:M, except that it allows a user thread to be
Examples
IRIX
HP-UX
Tru64 UNIX
Thread Libraries
Thread library provides programmer with API for creating
Pthreads
May be provided either as user-level or kernel-level
A POSIX standard (IEEE 1003.1c) API for thread creation and
synchronization
Signal Handling
1.
2.
3.
default
2.
user-defined
Mutex
Mutex is an abbreviation of mutual exclusion, and a mutex is a special
pthread_mutex_t.
A variable of type pthread_mutex_t needs to be initialized by the
NULL.
mutex variable, having the main thread initialize it and then the threads
call pthread _mutex_lock before entering the critical section, and they
call pthread_mutex_unlock when theyre done/finished with the critical
section.
state all the time as only one thread will access it at one time
Programming exercise
Please compile the programs using the follwing options
-lpthread o crit
-lpthread -o mutux
After compiling, run the above three programs in your lab sessions and
note down outputs in your note books.