03.Threads - From Processes to Threads 1 Processes, Threads...

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

View Full Document Right Arrow Icon
1 From Processes to Threads
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Processes, Threads and Processors Hardware can interpret N instruction streams at once Uniprocessor, N==1 Dual-core, N==2 Sun’s Niagara T2 (2007) N == 64, but 8 groups of 8 An OS can run 1 process on each processor at the same time Concurrent execution increases perforamnce An OS can run 1 thread on each processor at the same time
Background image of page 2
3 Processes and Threads Process abstraction combines two concepts Concurrency Each process is a sequential execution stream of instructions Protection Each process defines an address space Address space identifies all addresses that can be touched by the program Threads Key idea: separate the concepts of concurrency from protection A thread is a sequential execution stream of instructions A process defines the address space that may be shared by multiple threads Threads can execute on different cores on a multicore CPU (parallelism for performance) and can communicate with other threads by updating memory
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 The Case for Threads Consider the following code fragment for(k = 0; k < n; k++) a[k] = b[k] * c[k] + d[k] * e[k]; Is there a missed opportunity here? On a Uni-processor? On a Multi-processor?
Background image of page 4
5 The Case for Threads Consider a Web server get network message (URL) from client get URL data from disk compose response send response How well does this web server perform?
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 Programmer’s View void fn1(int arg0, int arg1, …) {…} main() { tid = CreateThread(fn1, arg0, arg1, …); } At the point CreateThread is called, execution continues in parent thread in main function, and execution starts at fn1 in the child thread, both in parallel (concurrently)
Background image of page 6
7 Introducing Threads A thread represents an abstract entity that executes a sequence of instructions It has its own set of CPU registers It has its own stack There is no thread-specific heap or data segment (unlike process) Threads are lightweight Creating a thread more efficient than creating a process. Communication between threads easier than btw. processes.
Background image of page 7

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

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

Page1 / 22

03.Threads - From Processes to Threads 1 Processes, Threads...

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