Operating System Concepts and Techniques Lecture 4 Thread M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques, First ed.,

Slides:



Advertisements
Similar presentations
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Advertisements

Chapter 3 Process Description and Control
Threads Irfan Khan Myo Thein What Are Threads ? a light, fine, string like length of material made up of two or more fibers or strands of spun cotton,
Slide 6-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Implementing Processes, Threads, and Resources.
Process Description and Control Chapter 3. Major Requirements of an Operating System Interleave the execution of several processes to maximize processor.
Processes CSCI 444/544 Operating Systems Fall 2008.
Page 1 Processes and Threads Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
1 Process Description and Control Chapter 3. 2 Process Management—Fundamental task of an OS The OS is responsible for: Allocation of resources to processes.
CSCE 351: Operating System Kernels
Process in Unix, Linux and Windows CS-3013 C-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
Ceng Operating Systems Chapter 2.1 : Processes Process concept Process scheduling Interprocess communication Deadlocks Threads.
1/23/2008CSCI 315 Operating Systems Design1 Processes Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
Operating Systems (CSCI2413) Lecture 3 Processes phones off (please)
1 Threads Chapter 4 Reading: 4.1,4.4, Process Characteristics l Unit of resource ownership - process is allocated: n a virtual address space to.
Processes in Unix, Linux, and Windows CS-502 Fall Processes in Unix, Linux, and Windows CS502 Operating Systems (Slides include materials from Operating.
Chapter 51 Threads Chapter 5. 2 Process Characteristics  Concept of Process has two facets.  A Process is: A Unit of resource ownership:  a virtual.
Process in Unix, Linux, and Windows CS-3013 A-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Process Management. Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication.
Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Chapter 3 Advanced Operating System
10/16/ Realizing Concurrency using the thread model B. Ramamurthy.
Processes and Threads CS550 Operating Systems. Processes and Threads These exist only at execution time They have fast state changes -> in memory and.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
CE Operating Systems Lecture 11 Windows – Object manager and process management.
B. RAMAMURTHY 10/24/ Realizing Concurrency using the thread model.
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
1 Chapter 2.1 : Processes Process concept Process concept Process scheduling Process scheduling Interprocess communication Interprocess communication Threads.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-1: Process Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Multiprogramming. Readings r Silberschatz, Galvin, Gagne, “Operating System Concepts”, 8 th edition: Chapter 3.1, 3.2.
Threads G.Anuradha (Reference : William Stallings)
Processes and Process Control 1. Processes and Process Control 2. Definitions of a Process 3. Systems state vs. Process State 4. A 2 State Process Model.
Chapter 2 Processes and Threads Introduction 2.2 Processes A Process is the execution of a Program More specifically… – A process is a program.
Operating System Concepts and Techniques Lecture 3 Process M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques, First ed.,
12/22/ Thread Model for Realizing Concurrency B. Ramamurthy.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Processes and Threads.
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
Windows Threading Colin Roby Jaewook Kim.
1 Process Description and Control Chapter 3. 2 Process A program in execution An instance of a program running on a computer The entity that can be assigned.
Cs431-cotter1 Processes and Threads Tanenbaum 2.1, 2.2 Crowley Chapters 3, 5 Stallings Chapter 3, 4 Silberschaz & Galvin 3, 4.
Operating System Concepts
Process Control Management Prepared by: Dhason Operating Systems.
Threads, SMP, and Microkernels Chapter 4. Processes and Threads Operating systems use processes for two purposes - Resource allocation and resource ownership.
Advanced Operating Systems CS6025 Spring 2016 Processes and Threads (Chapter 2)
B. RAMAMURTHY 5/10/2013 Amrita-UB-MSES Realizing Concurrency using the thread model.
7/9/ Realizing Concurrency using Posix Threads (pthreads) B. Ramamurthy.
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Process concept.
Process Management Process Concept Why only the global variables?
CS 6560: Operating Systems Design
OPERATING SYSTEMS CS3502 Fall 2017
Process Management Presented By Aditya Gupta Assistant Professor
Intro to Processes CSSE 332 Operating Systems
Threads and Locks.
Process Virtualization. Process Process is a program that has initiated its execution. A program is a passive entity; whereas a process is an active entity.
Structure of Processes
Processes in Unix, Linux, and Windows
Processes in Unix, Linux, and Windows
System Structure and Process Model
Process Description and Control
Process Description and Control
Threads and Concurrency
Threads Chapter 4.
Process Description and Control
Processes in Unix, Linux, and Windows
Chapter 2 Processes and Threads 2.1 Processes 2.2 Threads
Process Description and Control in Unix
Outline Process Management Process manager Hardware process
Presentation transcript:

Operating System Concepts and Techniques Lecture 4 Thread M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques, First ed., iUniverse Inc., To order: or

2 Thread Another entity which can run programs using CPU... Memory efficient when creating many entities from one program, simultaneously Sibling thread share the same executable file Sibling threads share resources hence reduce competition Sometimes called Light weight process because its creation takes less time than process

Thread types User level: Created and managed by user OS does not recognize it Kernel level: created and managed by OS Users can order its creation Hybrid: Created by user, managed jointly 3

Multithread process 4 Shared Items Private items … Process Thread 1 Thread 2 Thread n

Sibling threads common setting 5 SubjectDescription Address spaceCode, (parts of) data, and (parts of) results Open filesOpen files, file attributes, and means of referencing files ResourcesTapes, CDs, and many other hardware or software resources that are assigned to the process

Thread attributes 6 Thread identification information Thread ID Thread state information Thread-visible registers Location counter Condition code flags Stack pointers Thread control information Base priority Dynamic priority Thread processor affinity Thread execution time Suspension count Impersonation token Alert status Termination port Thread exit status

Process attributes in thread-based systems 7 Process identification information Process ID Process control information Security descriptor Base priority Default processor affinity Quota limit Execution time I/O counters VM operation counters Exception/debugging port Exit status

Thread state transition diagram in Windows 8 Standby Ready Waiting Transition Running Windows thread states The Corresponding state in the 3-state state model Ready Blocked Running Terminated Block/Suspend Run Assign resource Choose to run Preempt Unblock, resource assigned Completed Unblock, resource not assigned

Thread Creation and Termination Why create threads?  To run programs When is a thread created?  Whenever a process is created, its primary thread is created  Whenever a running thread, explicitly requests the execution of a service call that creates a thread 9

How is a Thread Created? Make sure the total number of threads created so far has not reached the limit Allocate a unique thread identification Allocate space for the Thread Control Block(TCB) and initialize appropriate fields Allocate space for thread context Allocate space for other required structures such as stacks and stack pointers and initialize proper fields Put the thread in one of the queues corresponding to the thread state 10

What are the Tools for Creating a Thread? #include void RegAttendance (void) // Regular attendance { while (1) { Beep (500, 10); // Make a beep sound printf (“ It is the time for the regular patient attendance \n ”); Sleep (15*60*1000); // Sleep for 15 minutes } } void ScheAttendance (void) // Scheduled attendance { int TimeSpan; while (1) { Beep (500, 10); // Make a beep sound printf (“ Enter the time span before next scheduled attendance\n “); scanf (“%d”, &TimeSpan); Sleep (TimeSpan*60*1000); // Sleep for “TimeSpan” minutes } } int main(void) { ANDLE thread1, thread2; thread1=CreateThread(0,0,(LPTHREAD_START_ROUTINE) RegAttendance,NULL,0,0); thread2=CreateThread(0,0,(LPTHREAD_START_ROUTINE) ScheAttendance,NULL,0,0); Sleep(INFINITE); return 0; } 11

How is a Thread terminated? All threads within the large body of a process are terminated when the process is terminated A thread can terminate itself by explicitly calling proper system calls or Win32-API routines such as ExitThread. By calling Win32-API routines such as TerminateThread form another thread in the same process, or another process if this process has the permission to do so, and has the handle to access the thread. 12

Summary Threads, in a thread-based operating system, are active objects to rum programs Thread methodology boosts operating system efficiency through better utilization of main memory and reduction of competing objects for resources Thread methodology increases collaboration between related program objects Threads of a process are not as independent as processes. Threads can share many items such as address space, resources, global variables, etc., Threading technique has its own difficulties. One thread may try to free a resource although its sibling threads have yet not finished with the resource. A thread may try to close a file that is needed by others Another difficulty is having a thread change a global variable while its sibling threads are unaware of 13

14 Find out The difference between copy-on-write method in Unix with thread concept in Windows How you can create a thread in Linux How you can create a thread in Unix The differences between Unix thread and Windows thread Why thread is called light weight process Benefits of thread compared to process

15 Any questions?