
Programming Shared
Memory I
Dr. Cem Özdo
˘
gan
LOGIK
Programming Shared
Memory
What is a Thread?
Threads Model
Why Threads?
Thread Basics: Creation
and Termination
Thread Creation
Thread Termination
9.3
What is Threads?
•
Technically, a thread is defined as an independent
stream of instructions that can be scheduled to run by
the operating system.
• Suppose that a main p r ogram contains a number of
procedur es (functions, subroutines, ...).
• Then suppose all of these procedures being able to be
scheduled to run simultaneously and/or independently.
• That would d escribe a "multi-threaded" program.
•
Before unders tanding a thread, one first needs to
understand a UNIX process.
•
Processes contain information about program resources
and program execution state.
• Thread s use and exist within these process resources,
• To be scheduled by the OS,
• R un as independent entities.
• A thread has its own independ ent flow of co ntrol as long
as its parent process exists (dies if the parent d ies!).
• A thread duplicates only the essential resources it needs.
•
A thread is "lightweight" because most of the overhead
has already been accomplished through the creation of its
process.