rec9-2010 - Threads Programming What is a Thread A thread...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Threads Programming
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
What is a Thread? A thread is a single sequential flow of control within a program.
Background image of page 2
Threads vs. Processes Creation of a new process using fork is expensive (time & memory). A thread (sometimes called a lightweight process ) does not require lots of memory or startup time.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
fork() fork() Process A Global Variables Code Stack Process B Global Variables Code Stack
Background image of page 4
pthread_create() Process A Thread 1 Global Variables Code Stack Process A Thread 2 Stack pthread_create()
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Multiple Threads Each process can include many threads. All threads of a process share: memory (program code and global data) open file/socket descriptors signal handlers and signal dispositions working environment (current directory, user ID, etc.)
Background image of page 6
Thread-Specific Resources Each thread has it’s own: Thread ID (integer) Stack, Registers, Program Counter errno (if not - errno would be useless!) Threads within the same process can communicate using shared memory.
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 22

rec9-2010 - Threads Programming What is a Thread A thread...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online