Nachos Threads and Concurrency

Slides:



Advertisements
Similar presentations
Processes CSCI 444/544 Operating Systems Fall 2008.
Advertisements

Process Description and Control A process is sometimes called a task, it is a program in execution.
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.
BINA RAMAMURTHY UNIVERSITY AT BUFFALO System Structure and Process Model 5/30/2013 Amrita-UB-MSES
Chapter 1 Process and Thread. 1.2 process The address space of a program – Text – Code – Stack – Heap A set of registers – PC – SP Other resources – Files.
Nachos Instructional OS CS 270, Tao Yang, Spring 2011.
CS333 Intro to Operating Systems Jonathan Walpole.
Chapter 2 Processes and Threads Introduction 2.2 Processes A Process is the execution of a Program More specifically… – A process is a program.
Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.
Concurrency, Processes, and System calls Benefits and issues of concurrency The basic concept of process System calls.
Department of Computer Science and Software Engineering
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
12/22/ Thread Model for Realizing Concurrency B. Ramamurthy.
1 Lecture 6 “Nachos” n nachos overview n directory structure n nachos emulated machine n nachos OS n nachos scheduler n nachos threads.
NachOS Threads System Road Map through the Code Lab 3.
Nachos Project 2 Lecturer: Hao-Hua Chu TA: Chun-Po Wang (Artoo) Date: 2008/10/14 Material Provided by Yuan-Hao Chang, Yung-Feng Lu.
1 Threads, SMP, and Microkernels Chapter 4. 2 Process Resource ownership - process includes a virtual address space to hold the process image Scheduling/execution-
Advanced Operating Systems CS6025 Spring 2016 Processes and Threads (Chapter 2)
1 Module 3: Processes Reading: Chapter Next Module: –Inter-process Communication –Process Scheduling –Reading: Chapter 4.5, 6.1 – 6.3.
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,
Chapter 4 – Thread Concepts
Realizing Concurrency using the thread model
Processes and threads.
Process Tables; Threads
Process Management Process Concept Why only the global variables?
Chapter 3: Process Concept
PROCESS MANAGEMENT IN MACH
Realizing Concurrency using the thread model
OPERATING SYSTEMS CS3502 Fall 2017
Day 12 Threads.
Chapter 4 – Thread Concepts
CS399 New Beginnings Jonathan Walpole.
Process Management Presented By Aditya Gupta Assistant Professor
Intro to Processes CSSE 332 Operating Systems
Threads & multithreading
System Structure and Process Model
System Structure and Process Model
Realizing Concurrency using Posix Threads (pthreads)
Lecture 2: Processes Part 1
System Structure B. Ramamurthy.
Realizing Concurrency using the thread model
System Structure and Process Model
Process Tables; Threads
Nachos Assignment#2 Priority Scheduling.
Process Description and Control
Process Description and Control
Threads and Concurrency
Threads Chapter 4.
Process Description and Control
Threads Chapter 5 2/17/2019 B.Ramamurthy.
Process Description and Control
Jonathan Walpole Computer Science Portland State University
Threads Chapter 5 2/23/2019 B.Ramamurthy.
Process Description and Control
Process Description and Control
Realizing Concurrency using the thread model
Realizing Concurrency using Posix Threads (pthreads)
Still Chapter 2 (Based on Silberchatz’s text and Nachos Roadmap.)
Process Description and Control
Realizing Concurrency using the thread model
Threads and Concurrency
Chapter 3: Processes.
Realizing Concurrency using Posix Threads (pthreads)
Chapter 2 Processes and Threads 2.1 Processes 2.2 Threads
CS510 Operating System Foundations
Process Description and Control
Outline Chapter 2 (cont) Chapter 3: Processes Virtual machines
Chapter 3: Process Concept
Threads CSE 2431: Introduction to Operating Systems
Presentation transcript:

Nachos Threads and Concurrency B.Ramamurthy 9/19/2018 B.Ramamurthy

Thread Unit of work A process has address space, registers, PC and stack (See Section 3, page 9.. in A Roadmap through Nachos for the detailed list) A thread has registers, program counter and stack, but the address space is shared with process that started it. This means that a user level thread could be invoked without assistance from the OS. This low overhead is one of the main advantages of threads. If a thread of a process is blocked, the process could go on. Concurrency: Many threads could be operating concurrently, on a multi threaded kernel. User level scheduling is simplified and realistic (bound, unbound, set concurrency, priorities etc.) Communication among the threads is easy and can be carried out without OS intervention. 9/19/2018 B.Ramamurthy

Thread requirements An execution state Independent PC working within the same process. An execution stack. Per-thread static storage for local variables. Access to memory and resources of the creator-process shared with all other threads in the task. Key benefits: less time to create than creating a new process, less time to switch, less time to terminate, more intuitive for implementing concurrency if the application is a collection of execution units. 9/19/2018 B.Ramamurthy

Threads and Processes A thread is a unit of work to a CPU. It is strand of control flow. A traditional UNIX process has a single thread that has sole possession of the process’s memory and resources. Threads within a process are scheduled and execute independently. Many threads may share the same address space. Each thread has its own private attributes: stack, program counter and register context. 9/19/2018 B.Ramamurthy

Threads and Processes (nachos model) 9/19/2018 B.Ramamurthy

Thread Operations Basic Operations associated with a thread are: Spawn : newly created into the ready state Block : waiting for an event Unblock : moved into ready from blocked Finish : exit after normal or abnormal termination. 9/19/2018 B.Ramamurthy

Nachos Threads (Section 3, .. RoadMap) Nachos process has an address space, a single thread of control, and other objects such as open file descriptors. Global variables are shared among threads. Nachos “scheduler” maintains a data structure called ready list which keeps track of threads that are ready to execute. Each thread has an associated state: READY, RUNNING, BLOCKED, JUST_CREATED Global variable currentThread always points to the currently running thread. 9/19/2018 B.Ramamurthy

Nachos Thread Description and Control Thread specific data: local data, stack and registers such as PC, SP. Control: Thread creation (Ex: fork) Thread schedule (Ex: yield) Thread synchronization (Ex: using barrier?) Code for execution (Ex: fork’s function parameter) 9/19/2018 B.Ramamurthy

Nachos Thread Class Thread //operations Thread *Thread(char *name); Thread *Thread(char *name, int priority); Fork (VoidFunctioNPtr func, int arg); void Yield(); // Scheduler::FindNextToRun() void Sleep(); // change state to BLOCKED void Finish(); // cleanup void CheckOverflow();// stack overflow void setStatus(ThreadStatus st); //ready, running.. // blocked char* getName(); void Print(); //print name //data int*stackTop; int machineState[MachineStateSize];//registers int* stack; ThreadStatus status; char* name;

Thread Control and Scheduling Switch (oldThread, newThread); // assembly language routine Threads that are ready kept in a ready list. The scheduler decides which thread to run next. Nachos Scheduling policy is: FIFO. 9/19/2018 B.Ramamurthy

Nachos Scheduler Class void ReadyTnRun(Thread* thread); Thread* FindNextToRun(); void Run(Thread* nextThread); void Print(); List* readyList; 9/19/2018 B.Ramamurthy

Barrier Synchronization Barrier is a synchronization primitive to synchronize among 2 or more threads. (n threads) Threads executing barrier synch wait until the expected number of threads execute the barrier synch primitive, at which time they are all released. This is similar to “rendevouz” concept in Ada language. 9/19/2018 B.Ramamurthy

Nachos Barrier.h class Barrier { public: Barrier(char *debugName, int size); ~Barrier(); char* getName() { return name; } // debugging assist void barrierSynch(); void print(); private: char* name; // for debugging // plus some other stuff you'll need to define }; 9/19/2018 B.Ramamurthy

Barrier Usage //Thread 2 //thread 1 Barrier bar = new Barrier (“sample”, 3); …. bar.barrierSynch(); // occurs a t(1) //thread blocked bar.barrierSynch(); //occurs at t(2) //thread blocked //Thread 3 bar.barrierSynch(); //occurs at t(3) //all threads are released You are required to implement a kernel level barriers and corresponding system calls to barriers From user programs 9/19/2018 B.Ramamurthy