User:Ffatmaa/sandbox

Threads

Threads concept :

- a thread is a lightweight process

each thread has its own program counter, register values, and stack. threads can share code, data and resources with other threads from same process.

- a process can be divided into many threads. some systems consider threads to be the fundamental execution unit. e.g., Windows 2000, XP

- motivation

- an application might need to perform several different tasks e.g., Web browser : display images/text, download page,. word processor : display text, read keystrokes, spell check, → can associate a thread with each task, execute concurrently.

- an application might need to perform the same task repeatedly e.g., Web server : receives many requests for pages, images,.. → can associate a thread with each request, execute concurrently.

Advantages of threads :

1) responsiveness multithreading means that part of the process can be executing even when others are blocked/busy.

2)resource sharing can save unnecessary duplication of data, files and other resources(no OS support needed for shared data/communication).

3)economy a since a thread shares code, data, and files much less overhead than creating processes.

4)concurrency if multiple processors, can split a process into threads and execute in parallel.