Threads - Operating Systems and Architecture - Lecture Slides, Slides of Computer Science

These are the Lecture Slides of Operating Systems and Architecture which includes Operating System Concerns, Basic Requirement, Difficulties, Need For Mutual Exclusion, Processes For Resources, Sharing etc.Key important points are: Threads, Resource Ownership, Allocated, Virtual Address, From Time to Time, Memory Plus Control, Child Process

Typology: Slides

2012/2013

Uploaded on 03/28/2013

ekana
ekana 🇮🇳

4

(44)

370 documents

1 / 44

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Threads, SMP, and
Microkernels
Chapter 4
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c

Partial preview of the text

Download Threads - Operating Systems and Architecture - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

Threads, SMP, and

Microkernels

Chapter 4

Two Characteristics of

Processes (1)

Resource ownership z A process is allocated a virtual address space to hold the process image z A process , from time to time, may be assigned main memory plus control of other resources, such as I/O channels, I/O devices, and files.

Dispatching and Thread

z These two characteristics are treated independently by the operating system z Resource of ownership is referred to as a process or task

z Dispatching is referred to as a thread

Thread

z A thread is a piece of program code executed in a serial fashion. z A thread is a dispatchable of work. It executes sequentially and is interruptable so that the processor can turn to another thread. z A process is a collection of one or more threads and associated system resources.

Threads and Processes

one processone thread

multiple processes one thread per process

multiple threads^ one process

multiple processes multiple threads per process

Single Threaded and

Multithreaded Process Models

Control^ Thread Block Stack^ User

Stack^ User

KernelStack

Kernel Stack

Address^ User Space

Address^ User Space Control^ Process Block

Control^ Process Block

Thread

Single-Threaded Process Model^ MultithreadedProcess Model

Control^ Thread Block Stack^ User Kernel Stack

Thread Control^ Thread Block Stack^ User Kernel Stack

Thread

Relationship Between

Threads and Processes

Threads:Process Description Example Systems 1:M A thread may migrate from one process environment to another. This allows a thread to be easily moved among distinct systems.

Ra (Clouds), Emerald

M:M Combines attributes of M: and 1:M cases

TRIX

Examples of threading & Multithreading

z MS-DOS supports a single process and a single thread.

z Java support a single process with multiple threads

z UNIX supports multiple user processes but only supports one thread per process

z Solaris and Windows NT supports multiple user processes , each of which supports multiple threads

thr_create API (Application Program

Interface) (1)

  1. The thr_create Function Prototype Include File: <thread. .h>

int thr_create( void* stackp, size_t stack_size, void* (funcp)(void), void* argp, long flags, thread_t* tid_p);

  1. Function of thr_create( ) The function creates a new thread to execute a function whose address is given in the funcp Dr. Ming Zhang

thr_create API (2)

  1. Return Success : 1 Failure: 0
  2. void* stackp

The address of a user-defined memory region. This memory is used as the new thread run- time stack. If the stackp value is NULL, the function allocates a stack region of stack_size bytes. 5 size_t stack_size The size of a user-defined memory region. This memory is used as the new thread run-time stack. If the stack_size value is 0, the function uses a system default value that is one Dr. Ming Zhang Docsity.com

thr_create API (4)

  1. long flags

The flags argument value may be zero, meaning that no special attributes are assigned to the new thread.

The flags value may using one or more of the following bit-flags:

THR_SUSPENDED: suspends the execution of the new thread until another thread calls the thr_continue function to enable it to execute

THR_NEW_LWP: Create a new LWP (LightWeight Process) along with the new Dr. Ming Zhang Docsity.com

thr_create API (5)

  1. thread_t* tid_p);

The new thread ID is return via the tid_p argument.

If the actual value of the tid_p argument is assigned NULL, no thread ID is returned.

The thread ID data type is thread_t.

Dr. Ming Zhang Docsity.com

Threads differ from Chile

Processes (1)

z Threads may be managed by either user- level library functions or the operating system kernel.

z Child processes as created by the fork system call are managed by the operating system kernel

Threads differ from Chile

Processes (2)

z All threads in a process share the same data and code segment.

z A child process has its own copy of virtual address space that is separate from its parent process.