Thread and Synchronization

Similar documents
PROCESS MANAGEMENT Operating Systems Design Euiseong Seo

Operating System Project / Lecture 1 Tasks and scheduling. Bon Keun Seo

Linux Kernel Development (LKD)

Chapter 4: Threads. Operating System Concepts 9 th Edit9on

Process. Heechul Yun. Disclaimer: some slides are adopted from the book authors slides with permission

Operating Systems 2 nd semester 2016/2017. Chapter 4: Threads

OPERATING SYSTEM. Chapter 4: Threads

Chapter 4: Threads. Operating System Concepts. Silberschatz, Galvin and Gagne

I.-C. Lin, Assistant Professor. Textbook: Operating System Concepts 8ed CHAPTER 4: MULTITHREADED PROGRAMMING

Process. Heechul Yun. Disclaimer: some slides are adopted from the book authors slides with permission 1

Chapter 4: Threads. Chapter 4: Threads

EPL372 Lab Exercise 2: Threads and pthreads. Εργαστήριο 2. Πέτρος Παναγή

Threads. What is a thread? Motivation. Single and Multithreaded Processes. Benefits

Chapter 4: Threads. Overview Multithreading Models Thread Libraries Threading Issues Operating System Examples Windows XP Threads Linux Threads

Chapter 4: Threads. Chapter 4: Threads

CS 475. Process = Address space + one thread of control Concurrent program = multiple threads of control

Multithreaded Programming

Dynamic Recrea,on of Kernel Data Structures for Live Forensics. Andrew Case, Lodovico Marziale, Golden G. Richard III DFRWS 2010

What we will learn. Multi Process Systems: Processes &Threads. Architectural support: Processor Modes. Processes (classic vs.

Multithreading. Reading: Silberschatz chapter 5 Additional Reading: Stallings chapter 4

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

Semantics of fork() and exec()

Computer Systems Laboratory Sungkyunkwan University

EI 338: Computer Systems Engineering (Operating Systems & Computer Architecture)

4. Concurrency via Threads

Processes. Dr. Yingwu Zhu

Thread and Synchronization

Chapter 4: Multi-Threaded Programming

Thread Concept. Thread. No. 3. Multiple single-threaded Process. One single-threaded Process. Process vs. Thread. One multi-threaded Process

THREADS. Jo, Heeseung

SMD149 - Operating Systems

Lecture 3: Processes. CMPUT 379, Section A1, Winter 2014 January 13, 15 and 17

CS307: Operating Systems

Chapter 4: Threads. Operating System Concepts 9 th Edition

Chapter 3: Processes. Operating System Concepts 9 th Edit9on

Introduction to PThreads and Basic Synchronization

Introduction to the Linux Kernel. Hao-Ran Liu

CHAPTER 3 - PROCESS CONCEPT

Last class: Today: Thread Background. Thread Systems

CS 450 Operating System Week 4 Lecture Notes

Definition Multithreading Models Threading Issues Pthreads (Unix)

Concurrency, Thread. Dongkun Shin, SKKU

Agenda Process Concept Process Scheduling Operations on Processes Interprocess Communication 3.2

4.8 Summary. Practice Exercises

Chapter 5: Threads. Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux Threads Java Threads

Threads. Still Chapter 2 (Based on Silberchatz s text and Nachos Roadmap.) 3/9/2003 B.Ramamurthy 1

Chapter 4: Threads. Operating System Concepts 9 th Edition

Processes and Threads

What is a process. Ausgewählte Betriebssysteme. Process state. task_struct. Processes and Threads

Processes Topics Processes Context switching Scheduling

Chapter 3 Process Description and Control

Processes and Threads. Processes and Threads. Processes (2) Processes (1)

Chapter 3: Processes. Operating System Concepts 8th Edition

POSIX Threads: a first step toward parallel programming. George Bosilca

Prepared by Prof. Hui Jiang Process. Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University

Lecture Topics. Announcements. Today: Threads (Stallings, chapter , 4.6) Next: Concurrency (Stallings, chapter , 5.

Process. Prepared by Prof. Hui Jiang Dept. of EECS, York Univ. 1. Process in Memory (I) PROCESS. Process. How OS manages CPU usage? No.

CS 326: Operating Systems. Process Execution. Lecture 5

CSE 153 Design of Operating Systems Fall 2018

Concurrent Server Design Multiple- vs. Single-Thread

For use by students enrolled in #71251 CSE430 Fall 2012 at Arizona State University. Do not use if not enrolled.

Lecture Contents. 1. Overview. 2. Multithreading Models 3. Examples of Thread Libraries 4. Summary

Questions answered in this lecture: CS 537 Lecture 19 Threads and Cooperation. What s in a process? Organizing a Process

Scheduling policy. Reference: ULK3e 7.1. Scheduling in Linux 1 / 20

Chapter 3: Processes

518 Lecture Notes Week 3

Chapter 4: Multithreaded Programming

CS 378 (Spring 2003)

CS 318 Principles of Operating Systems

Threads. CS-3013 Operating Systems Hugh C. Lauer. CS-3013, C-Term 2012 Threads 1

Getting to know you. Anatomy of a Process. Processes. Of Programs and Processes

Chapter 5: Threads. Outline

Processes and Threads

COP 4610: Introduction to Operating Systems (Spring 2015) Chapter 4: Threads. Zhi Wang Florida State University

CS Lecture 3! Threads! George Mason University! Spring 2010!

Yi Shi Fall 2017 Xi an Jiaotong University

Chapter 4: Multithreaded

CISC2200 Threads Spring 2015

PROCESSES. Jo, Heeseung

Processes. Jo, Heeseung

Motivation. Threads. Multithreaded Server Architecture. Thread of execution. Chapter 4

THE PROCESS ABSTRACTION. CS124 Operating Systems Winter , Lecture 7

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

Chapter 4: Threads. Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux Threads Java Threads. Operating System Concepts

Chapter 4: Multithreaded Programming. Operating System Concepts 8 th Edition,

Outline. Threads. Single and Multithreaded Processes. Benefits of Threads. Eike Ritter 1. Modified: October 16, 2012

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

Chapter 4: Threads. Chapter 4: Threads. Overview Multicore Programming Multithreading Models Thread Libraries Implicit Threading Threading Issues

Operating Systems 16 - CS 323 Assignment #2

Processes & Threads. Today. Next Time. ! Process concept! Process model! Implementing processes! Multiprocessing once again. ! More of the same J

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

CS510 Operating System Foundations. Jonathan Walpole

Processes and Threads

Chapter 3: Process Concept

Chapter 3: Process Concept

Using kgdb and the kgdb Internals

CS333 Intro to Operating Systems. Jonathan Walpole

IMPLEMENTATION OF SIGNAL HANDLING. CS124 Operating Systems Fall , Lecture 15

Threads, SMP, and Microkernels. Chapter 4

Computer Science 322 Operating Systems Mount Holyoke College Spring Topic Notes: Processes and Threads

Transcription:

Thread and Synchronization Task Model (Module 18) Yann-Hang Lee Arizona State University yhlee@asu.edu (480) 727-7507 Summer 2014 Real-time Systems Lab, Computer Science and Engineering, ASU

Why Talk About This Subject A thread of program execution How a program start and end its execution waiting for an event or a resource, delay a period, etc. For concurrent operations multiple threads of program execution How can we make this happen? support for program execution sharing of resources scheduling communication between threads Real-time Systems Lab, Computer Science and Engineering, ASU 1

Thread and Process Process: an entity to which system resources (CPU time, memory, etc.) are allocated an address space with 1 or more threads executing within that address space, and the required system resources for those threads Thread: a sequence of control within a process and shares the resources in that process Lightweight process (LWP): LWP may share resources: address space, open files, clone or fork share or not share address space, file descriptor, etc. In Linux kernel, threads are implemented as standard processes (LWP) that shares certain resources with other processes, and there is no special scheduling semantics or data structures to represent threads Real-time Systems Lab, Computer Science and Engineering, ASU 2

Why Threads Advantages: the overhead for creating a thread is significantly less than that for creating a process multitasking, i.e., one process serves multiple clients switching between threads requires the OS to do much less work than switching between processes Drawbacks: not as widely available as the process features writing multithreaded programs require more careful thought more difficult to debug than single threaded programs for single processor machines, creating several threads in a program may not necessarily produce an increase in performance (only so many CPU cycles to be had) Real-time Systems Lab, Computer Science and Engineering, ASU 3

POSIX Thread (pthread) IEEE's POSIX Threads Model: programming models for threads in a UNIX platform pthreads are included in the international standards pthreads programming model: creation of threads managing thread execution managing the shared resources of the process main thread: initial thread created when main() is invoked has the ability to create daughter threads if the main thread returns, the process terminates even if there are running threads in that process to explicitly avoid terminating the entire process, use pthread_exit() Real-time Systems Lab, Computer Science and Engineering, ASU 4

Linux task_struct struct task_struct { /* Linux/include/linux/sched.h */ volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */ void *stack; atomic_t usage; unsigned int flags; /* per process flags, defined below */ unsigned int ptrace; int lock_depth; /* BKL (big kernel lock) lock depth */ int prio, static_prio, normal_prio; unsigned int rt_priority; const struct sched_class *sched_class;.. struct mm_struct *mm, *active_mm; struct thread_struct thread; /* CPU-specific state of this task */ struct fs_struct *fs; /* filesystem information */ struct files_struct *files; /* open file information */ Real-time Systems Lab, Computer Science and Engineering, ASU 5

Process -- task_struct data structure state: process state TASK_RUNNING: executing TASK_INTERRUPTABLE: suspended (sleeping) TASK_UNINTERRUPTABLE: (no process of signals) TASK_STOPPED (stopped by SIGSTOP) TASK_TRACED (being monitored by other processes such as debuggers) EXIT_ZOMBIE (terminated before waiting for parent) EXIT_DEAD thread_info: low-level information for the process mm: pointers to memory area descriptors tty: tty associated with the process fs: current directory files: pointers to file descriptors signal: signals received. Real-time Systems Lab, Computer Science and Engineering, ASU 6

Linux Processor State /* This is the TSS (task State Segment) defined by the hardware and saved in stack. */ struct x86_hw_tss { unsigned short back_link, blh; sp0; unsigned short ss0, ss0h; sp1; unsigned short ss1, ss1h; /* ss1 caches MSR_IA32_SYSENTER_CS: */ sp2; unsigned short ss2, ss2h; cr3; ip; flags; ax; cx; dx; bx; /* For ARM, Linux/arch/arm/include/asm/thread_info.h., Real-time Systems Lab, Computer Science and Engineering, ASU 7

Linux Thread State Transition Ready Preempted Wait satisfied Blocked Start Scheduled Wait for resource Running Done or cancelled Terminated Real-time Systems Lab, Computer Science and Engineering, ASU 8

Task Management in vxworks Execution executing pending ready delayed Ready Blocked taskinit() suspended Task structure in task control block priority(initial and inherited), stack frame, task current state, entry point, processor states (program counter, registers) callback function (hook) pointers for OS events spare variables Real-time Systems Lab, Computer Science and Engineering, ASU 9

VxWorks Task States typedef struct windtcb /* WIND_TCB - task control block */ { char * name; /* 0x34: pointer to task name */ UINT status; /* 0x3c: status of task */ UINT priority; /* 0x40: task's current priority */ UINT prinormal; /* 0x44: task's normal priority */ UINT primutexcnt; /* 0x48: nested priority mutex owned */ UINT lockcnt; /* 0x50: preemption lock count */ FUNCPTR entry; /* 0x74: entry point of task */ char * pstackbase;/* 0x78: points to bottom of stack */ char * pstacklimit; /* 0x7c: points to stack limit */ char * pstackend; /* 0x80: points to init stack limit */ #if (CPU_FAMILY==I80X86) /* function declarations */ EXC_INFO excinfo; /* 0x118: exception info */ REG_SET regs; /* 0x12c: register set */ DBG_INFO_NEW dbginfo0; /* 0x154: debug info */ #endif /* CPU_FAMILY==I80X86 */ Real-time Systems Lab, Computer Science and Engineering, ASU 10