POSIX Threads (Pthreads) Standard – Pthreads-Win32, POSIX Thread for Windows – Scheduler Activations (I.E

Total Page:16

File Type:pdf, Size:1020Kb

POSIX Threads (Pthreads) Standard – Pthreads-Win32, POSIX Thread for Windows – Scheduler Activations (I.E Distributed Systems LEEC (2005/06 – 2º Sem.) Processes João Paulo Carvalho Universidade Técnica de Lisboa / Instituto Superior Técnico Outline • Processes and Threads –Overview – Processes, threads and fibers – Light weight processes • Client and Server Processes • Code migration • Software Agents • Case Studies J.P. Carvalho Sistemas Distribuídos 2005/2006 2 Processes Review • Multiprogramming versus multiprocessing • Kernel data structure: process control block (PCB) • Each process has an address space – Contains code, global and local variables.. • Process state transitions • Uniprocessor scheduling algorithms – Round-robin, shortest job first, FIFO, lottery scheduling, EDF • Performance metrics: throughput, CPU utilization, turnaround time, response time, fairness J.P. Carvalho Sistemas Distribuídos 2005/2006 3 Processes (2) Review - Scheduling • Priority queues: multiples queues, each with a different priority – Use strict priority scheduling – Example: page swapper, kernel tasks, real-time tasks, user tasks • Multi-level feedback queue – Multiple queues with priority – Processes dynamically move from one queue to another • Depending on priority/CPU characteristics – Gives higher priority to I/O bound or interactive tasks – Lower priority to CPU bound tasks – Round robin at each level J.P. Carvalho Sistemas Distribuídos 2005/2006 4 Processes and Threads • Processes – Typically independent – Carry considerable state information – Have separate address spaces – Interact only through system-provided inter-process communication mechanisms • Threads – Share the state information of a single process – Share memory and other resources directly • Context switching between threads in the same process is typically faster than context switching between processes. – Systems like Windows XP and OS/2 are said to have "cheap" threads and "expensive" processes, while in other operating systems there is not so big a difference. J.P. Carvalho Sistemas Distribuídos 2005/2006 5 Processes and Threads(2) • Multi-threaded program advantage: – Operates faster on computer systems that have multiple CPUs, CPUs with multiple cores, or across a cluster of machines • Why? – Because the threads of the program naturally lend themselves for truly concurrent execution • The programmer needs to be careful to avoid race conditions, and other non-intuitive behaviors • In order for data to be correctly manipulated, threads will often need to rendezvous in time in order to process the data in the correct order • Threads may also require atomic operations (often implemented using semaphores) in order to prevent common data from being simultaneously modified, or read while in the process of being modified. Careless use of such primitives can lead to deadlocks J.P. Carvalho Sistemas Distribuídos 2005/2006 6 Processes and Threads (3) • Thread Scheduling: – Preemptive multithreading • Allows the operating system to determine when a context switch should occur – Disadvantage: the system may make a context switch at an inappropriate time – Cooperative multithreading • The threads themselves relinquish control once they are at a stopping point – Disadvantage: can create problems if a thread is waiting for a resource to become available). J.P. Carvalho Sistemas Distribuídos 2005/2006 7 Why use Threads? • Large multiprocessors need many computing entities (one per CPU) • Threads can execute in parallel on multiprocessors • Switching between processes incurs high overhead. By using threads, an application can avoid per-process overheads • Thread creation and deletion are also cheaper than processes • Threads have full access to a process address space (easy sharing) • Threads retain the idea of sequential processes with blocking system calls, and yet achieve parallelism • Software engineering perspective – Applications are easier to structure as a collection of thread where each thread performs several [mostly independent] tasks J.P. Carvalho Sistemas Distribuídos 2005/2006 8 Thread Management • Creation and deletion of threads – Static versus dynamic • Critical sections – Synchronization primitives: blocking, spin-lock (busy-wait) – Condition variables • Global thread variables • Kernel versus user-level threads J.P. Carvalho Sistemas Distribuídos 2005/2006 9 User-level Threads User-Level Threads, aka Fibers • Threads managed by a threads library – Kernel is unaware of presence of threads • Advantages: – No kernel modifications needed to support threads – Efficient: creation/deletion/switches don’t need system calls – Flexibility in scheduling: library can use different scheduling algorithms, can be application dependent • Disadvantages – Need to avoid blocking system calls (a thread blocks the entire process) – Threads compete for resources within a process – Do not take advantage of multiprocessors (no real parallelism) J.P. Carvalho Sistemas Distribuídos 2005/2006 10 User-level Threads (2) User-level Thread Example J.P. Carvalho Sistemas Distribuídos 2005/2006 11 Kernel-level Threads Kernel Level Threads • Kernel aware of the presence of threads – Blocked threads do not block other threads in the same process – Better but more expensive scheduling decisions – Better for multiprocessors, more overheads for uniprocessors J.P. Carvalho Sistemas Distribuídos 2005/2006 12 Light-Weight Processes LWP •Goal:Implement “fibers” that do not block the associated process – NOTE: Many systems (e.g. Java), do not make a distinction between Kernel Threads and LWP (Kernel Threads are implemented as LWP) • Several LWPs per process • Multithreaded applications – create multiple threads, assign threads to LWPs (one-one, many-one, many-many) • Each LWP, when scheduled, searches for a runnable thread on a shared thread table (two-level scheduling) – Shared thread table: no kernel support needed • If a LWP thread blocks on a system call, switch to kernel mode and, if possible, switch OS context to another LWP of the same process J.P. Carvalho Sistemas Distribuídos 2005/2006 13 Light-Weight Processes(2) LWP Example J.P. Carvalho Sistemas Distribuídos 2005/2006 14 P T F Example (extracted from Wikipedia) N N N A program running on DOS. The program can only do one thing at a time. Windows 3.1 running on top of DOS. All Windows programs are run within a single process, so the programs can corrupt each N N Y other's memory space. A poorly written program could corrupt data it didn't own, causing the infamous General Protection Fault, or neglect to yield the processor, resulting in a hung system. Amiga OS's original implementation. The operating system had full thread support, allowing multiple applications to run independently of each other which are scheduled by the kernel. The lack of process support resulted in a more efficient system N Y N (by avoiding the overhead of memory protection), with the price that application bugs could easily crash the entire computer. Many commercial RTOSes, such as vxWorks, also support this model. Mac OS 9 supported fibers through Apple's Thread Manager and threads through Apple's Multiprocessing Services, which N Y Y works with the nanokernel intoduced in Mac OS 8.6 to provide thread support, but still use the MultiFinder's way of managing applications. Most early implementations of Unix. The operating system could run more than one program at a time, and programs were protected from each other. If a program behaved badly, it could crash its process ending that instance of the program without Y N N disrupting the operating system or other programs. However, due to this protection, sharing information between programs was error-prone (using techniques like shared memory) and expensive (using techniques like message passing). Performing any tasks asynchronously required an expensive fork() system call. Sun OS before Solaris. Sun OS is Sun Microsystem's version of Unix. Sun OS implemented "green threads" in order to allow a single process to asynchronously perform multiple tasks such as playing a sound, repainting a window, and responding to user Y N Y events such as clicking the stop button. Although processes were pre-emptively scheduled, the "green threads" or fibers were co-operatively multitasked. Often this model was used before real threads were implemented. This model is still used in microcontrollers and embedded devices. This is the most common case for applications running on Windows NT 3.51 SP3+, Windows 2000, Windows XP, Mac OS X, Linux, and other modern operating systems. Although each of these operating systems allows the programmer to implement fibers or use a fiber library, most programmers do not use fibers in their applications. The programs are multithreaded and run Y Y N inside a multitasking operating system, but perform no user-level context switching. On the typical home computer, most running processes have two or more threads. A few processes will have a single thread. Usually these processes are services running without user interaction. Typically there are no processes using fibers. Almost all operating systems after 1995 fall into this category. The use of threads to perform concurrent operations is the most Y Y Y commonJ.P. choice, Carvalho although there are also multi-process Sistemas andDistribuídos multi-fiber applications. 2005/2006 Threads are used, for example, to enable 15 a program to render its graphical user interface while waiting for input from the user or performing a task like spell checking. Threads Implementations • There are many different and incompatible implementations of threading, including both kernel-level
Recommended publications
  • Events, Co-Routines, Continuations and Threads OS (And Application)Execution Models System Building
    Events, Co-routines, Continuations and Threads OS (and application)Execution Models System Building General purpose systems need to deal with • Many activities – potentially overlapping – may be interdependent • Activities that depend on external phenomena – may requiring waiting for completion (e.g. disk read) – reacting to external triggers (e.g. interrupts) Need a systematic approach to system structuring © Kevin Elphinstone 2 Construction Approaches Events Coroutines Threads Continuations © Kevin Elphinstone 3 Events External entities generate (post) events. • keyboard presses, mouse clicks, system calls Event loop waits for events and calls an appropriate event handler. • common paradigm for GUIs Event handler is a function that runs until completion and returns to the event loop. © Kevin Elphinstone 4 Event Model The event model only requires a single stack Memory • All event handlers must return to the event loop CPU Event – No blocking Loop – No yielding PC Event SP Handler 1 REGS Event No preemption of handlers Handler 2 • Handlers generally short lived Event Handler 3 Data Stack © Kevin Elphinstone 5 What is ‘a’? int a; /* global */ int func() { a = 1; if (a == 1) { a = 2; } No concurrency issues within a return a; handler } © Kevin Elphinstone 6 Event-based kernel on CPU with protection Kernel-only Memory User Memory CPU Event Loop Scheduling? User PC Event Code SP Handler 1 REGS Event Handler 2 User Event Data Handler 3 Huh? How to support Data Stack multiple Stack processes? © Kevin Elphinstone 7 Event-based kernel on CPU with protection Kernel-only Memory User Memory CPU PC Trap SP Dispatcher User REGS Event Code Handler 1 User-level state in PCB Event PCB Handler 2 A User Kernel starts on fresh Timer Event Data stack on each trap (Scheduler) PCB B No interrupts, no blocking Data Current in kernel mode Thead PCB C Stack Stack © Kevin Elphinstone 8 Co-routines Originally described in: • Melvin E.
    [Show full text]
  • Designing an Ultra Low-Overhead Multithreading Runtime for Nim
    Designing an ultra low-overhead multithreading runtime for Nim Mamy Ratsimbazafy Weave [email protected] https://github.com/mratsim/weave Hello! I am Mamy Ratsimbazafy During the day blockchain/Ethereum 2 developer (in Nim) During the night, deep learning and numerical computing developer (in Nim) and data scientist (in Python) You can contact me at [email protected] Github: mratsim Twitter: m_ratsim 2 Where did this talk came from? ◇ 3 years ago: started writing a tensor library in Nim. ◇ 2 threading APIs at the time: OpenMP and simple threadpool ◇ 1 year ago: complete refactoring of the internals 3 Agenda ◇ Understanding the design space ◇ Hardware and software multithreading: definitions and use-cases ◇ Parallel APIs ◇ Sources of overhead and runtime design ◇ Minimum viable runtime plan in a weekend 4 Understanding the 1 design space Concurrency vs parallelism, latency vs throughput Cooperative vs preemptive, IO vs CPU 5 Parallelism is not 6 concurrency Kernel threading 7 models 1:1 Threading 1 application thread -> 1 hardware thread N:1 Threading N application threads -> 1 hardware thread M:N Threading M application threads -> N hardware threads The same distinctions can be done at a multithreaded language or multithreading runtime level. 8 The problem How to schedule M tasks on N hardware threads? Latency vs 9 Throughput - Do we want to do all the work in a minimal amount of time? - Numerical computing - Machine learning - ... - Do we want to be fair? - Clients-server - Video decoding - ... Cooperative vs 10 Preemptive Cooperative multithreading:
    [Show full text]
  • An Ideal Match?
    24 November 2020 An ideal match? Investigating how well-suited Concurrent ML is to implementing Belief Propagation for Stereo Matching James Cooper [email protected] OutlineI 1 Stereo Matching Generic Stereo Matching Belief Propagation 2 Concurrent ML Overview Investigation of Alternatives Comparative Benchmarks 3 Concurrent ML and Belief Propagation 4 Conclusion Recapitulation Prognostication 5 References Outline 1 Stereo Matching Generic Stereo Matching Belief Propagation 2 Concurrent ML Overview Investigation of Alternatives Comparative Benchmarks 3 Concurrent ML and Belief Propagation 4 Conclusion Recapitulation Prognostication 5 References Outline 1 Stereo Matching Generic Stereo Matching Belief Propagation 2 Concurrent ML Overview Investigation of Alternatives Comparative Benchmarks 3 Concurrent ML and Belief Propagation 4 Conclusion Recapitulation Prognostication 5 References Stereo Matching Generally SM is finding correspondences between stereo images Images are of the same scene Captured simultaneously Correspondences (`disparity') are used to estimate depth SM is an ill-posed problem { can only make best guess Impossible to perform `perfectly' in general case Stereo Matching ExampleI (a) Left camera's image (b) Right camera's image Figure 1: The popular 'Tsukuba' example stereo matching images, so called because they were created by researchers at the University of Tsukuba, Japan. They are probably the most widely-used benchmark images in stereo matching. Stereo Matching ExampleII (a) Ground truth disparity map (b) Disparity map generated using a simple Belief Propagation Stereo Matching implementation Figure 2: The ground truth disparity map for the Tsukuba images, and an example of a possible real disparity map produced by using Belief Propagation Stereo Matching. The ground truth represents what would be expected if stereo matching could be carried out `perfectly'.
    [Show full text]
  • Tcl and Java Performance
    Tcl and Java Performance http://ptolemy.eecs.berkeley.edu/~cxh/java/tclblend/scriptperf/scriptperf.html Tcl and Java Performance by H. John Reekie, University of California at Berkeley Christopher Hylands, University of California at Berkeley Edward A. Lee, University of California at Berkeley Abstract Combining scripting languages such as Tcl with lower−level programming languages such as Java offers new opportunities for flexible and rapid software development. In this paper, we benchmark various combinations of Tcl and Java against the two languages alone. We also provide some comparisons with JavaScript. Performance can vary by well over two orders of magnitude. We also uncovered some interesting threading issues that affect performance on the Solaris platform. "There are lies, damn lies and statistics" This paper is a work in progress, we used the information here to give our group some generalizations on the performance tradeoffs between various scripting languages. Updating the timing results to include JDK1.2 with a Just In Time (JIT) compiler would be useful. Introduction There is a growing trend towards integration of multiple languages through scripting. In a famously controversial white paper (Ousterhout 97), John Ousterhout, now of Scriptics Corporation, argues that scripting −− the use of a high−level, untyped, interpreted language to "glue" together components written in a lower−level language −− provides greater reuse benefits that other reuse technologies. Although traditionally a language such as C or C++ has been the lower−level language, more recent efforts have focused on using Java. Recently, Sun Microsystems laboratories announced two products aimed at fulfilling this goal with the Tcl and Java programming languages.
    [Show full text]
  • Thread Scheduling in Multi-Core Operating Systems Redha Gouicem
    Thread Scheduling in Multi-core Operating Systems Redha Gouicem To cite this version: Redha Gouicem. Thread Scheduling in Multi-core Operating Systems. Computer Science [cs]. Sor- bonne Université, 2020. English. tel-02977242 HAL Id: tel-02977242 https://hal.archives-ouvertes.fr/tel-02977242 Submitted on 24 Oct 2020 HAL is a multi-disciplinary open access L’archive ouverte pluridisciplinaire HAL, est archive for the deposit and dissemination of sci- destinée au dépôt et à la diffusion de documents entific research documents, whether they are pub- scientifiques de niveau recherche, publiés ou non, lished or not. The documents may come from émanant des établissements d’enseignement et de teaching and research institutions in France or recherche français ou étrangers, des laboratoires abroad, or from public or private research centers. publics ou privés. Ph.D thesis in Computer Science Thread Scheduling in Multi-core Operating Systems How to Understand, Improve and Fix your Scheduler Redha GOUICEM Sorbonne Université Laboratoire d’Informatique de Paris 6 Inria Whisper Team PH.D.DEFENSE: 23 October 2020, Paris, France JURYMEMBERS: Mr. Pascal Felber, Full Professor, Université de Neuchâtel Reviewer Mr. Vivien Quéma, Full Professor, Grenoble INP (ENSIMAG) Reviewer Mr. Rachid Guerraoui, Full Professor, École Polytechnique Fédérale de Lausanne Examiner Ms. Karine Heydemann, Associate Professor, Sorbonne Université Examiner Mr. Etienne Rivière, Full Professor, University of Louvain Examiner Mr. Gilles Muller, Senior Research Scientist, Inria Advisor Mr. Julien Sopena, Associate Professor, Sorbonne Université Advisor ABSTRACT In this thesis, we address the problem of schedulers for multi-core architectures from several perspectives: design (simplicity and correct- ness), performance improvement and the development of application- specific schedulers.
    [Show full text]
  • Table of Contents
    Parallel Programming Models Lawrence Rauchwerger http://parasol.tamu.edu Table of Contents Introduction to Parallelism Introduction to Programming Models Shared Memory Programming Message Passing Programming Shared Memory Models PGAS Languages Other Programming Models 1 Acknowledgement Material in this course has been adapted from various (cited) authoritative sources Presentation has been put together with the help of Dr. Mauro Bianco, Antoniu Pop, Tim Smith and Nathan Thomas – Parasol Lab, Department of Computer Science, Texas A&M University. What Will You Get from Class Ideas about parallel processing Different approaches to parallel programming Additional material in your classnotes 2 Table of Contents Introduction to Parallelism – What is Parallelism ? What is the Goal ? Introduction to Programming Models Shared Memory Programming Message Passing Programming Shared Memory Models PGAS Languages Other Programming Models Introduction to Parallelism Sequential Computing – Single CPU executes stream of instructions. Adapted from: http://www.llnl.gov/computing/tutorials/parallel_comp 3 Introduction to Parallelism Parallel computing – Partition problem into multiple, concurrent streams of instructions. Classification Flynn’s Taxonomy (1966-now) Nowadays SISD SIMD SPMD Single Instruction Single Instruction Single Program Single Data Multiple Data Multiple Data MISD MIMD MPMD Multiple Instructions Multiple Instructions Multiple Program Single Data Multiple Data Multiple Data • Execution models impact the above programming model • Traditional computer is SISD • SIMD is data parallelism while MISD is pure task parallelism • MIMD is a mixed model (harder to program) • SPMD and MPMD are less synchronized than SIMD and MIMD • SPMD is most used model, but MPMD is becoming popular 4 Introduction to Parallelism Goal of parallel computing – Save time - reduce wall clock time.
    [Show full text]
  • Comparison of Concurrency Frameworks for the Java Virtual Machine
    Universität Ulm Fakultät für Ingenieurwissenschaften und Informatik Institut für Verteilte Systeme, Bachelorarbeit im Studiengang Informatik Comparison of Concurrency Frameworks for the Java Virtual Machine Thomas Georg Kühner vorgelegt am 25. Oktober 2013 VS-B13-2013 Gutachter Prof. Dr. Frank Kargl Fassung vom: December 8, 2013 cbnd Diese Arbeit ist lizensiert unter der Creative Commons Namensnennung-Keine kommerzielle Nutzung-Keine Bearbeitung 3.0 Deutschland Lizenz. Nähere Informationen finden Sie unter: http://creativecommons.org/licenses/by-nc-nd/3.0/de/ oder senden Sie einen Brief an: Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. Contents 1. Introduction 1 1.1. Motivation..........................................1 1.2. Scope of this Thesis.....................................2 1.3. Methodology........................................2 1.4. Road Map for this thesis..................................2 2. Basics and Background about Concurrency and Concurrent Programming3 2.1. Terminology.........................................3 2.2. Small History of Concurrency Theory..........................5 2.3. General Programming Models for Concurrency....................6 2.4. Traditional Concurrency Issues..............................7 2.4.1. Race Condition...................................7 2.4.2. Dead-Lock......................................8 2.4.3. Starvation......................................8 2.4.4. Priority Inversion..................................9 2.5. Summary...........................................9
    [Show full text]
  • Threading and GUI Issues for R
    Threading and GUI Issues for R Luke Tierney School of Statistics University of Minnesota March 5, 2001 Contents 1 Introduction 2 2 Concurrency and Parallelism 2 3 Concurrency and Dynamic State 3 3.1 Options Settings . 3 3.2 User Defined Options . 5 3.3 Devices and Par Settings . 5 3.4 Standard Connections . 6 3.5 The Context Stack . 6 3.5.1 Synchronization . 6 4 GUI Events And Blocking IO 6 4.1 UNIX Issues . 7 4.2 Win32 Issues . 7 4.3 Classic MacOS Issues . 8 4.4 Implementations To Consider . 8 4.5 A Note On Java . 8 4.6 A Strategy for GUI/IO Management . 9 4.7 A Sample Implementation . 9 5 Threads and GUI’s 10 6 Threading Design Space 11 6.1 Parallelism Through HL Threads: The MXM Options . 12 6.2 Light-Weight Threads: The XMX Options . 12 6.3 Multiple OS Threads Running One At A Time: MSS . 14 6.4 Variations on OS Threads . 14 6.5 SMS or MXS: Which To Choose? . 14 7 Light-Weight Thread Implementation 14 1 March 5, 2001 2 8 Other Issues 15 8.1 High-Level GUI Interfaces . 16 8.2 High-Level Thread Interfaces . 16 8.3 High-Level Streams Interfaces . 16 8.4 Completely Random Stuff . 16 1 Introduction This document collects some random thoughts on runtime issues relating to concurrency, threads, GUI’s and the like. Some of this is extracted from recent R-core email threads. I’ve tried to provide lots of references that might be of use.
    [Show full text]
  • Kernel Threads
    CSMC 412 Operating Systems Prof. Ashok K Agrawala © 2019 Ashok Agrawala February 20 1 Threads & Concurrency Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 Threads • Overview • Multicore Programming • Multithreading Models • Thread Libraries • Implicit Threading • Threading Issues • Operating System Examples February 20 Copyright 2018 Silberschatz, Gavin & Gagne 3 Objectives • To introduce the notion of a thread—a fundamental unit of CPU utilization that forms the basis of multithreaded computer systems • To discuss the APIs for the Pthreads, Windows, and Java thread libraries • To explore several strategies that provide implicit threading • To examine issues related to multithreaded programming • To cover operating system support for threads in Windows and Linux February 20 Copyright 2018 Silberschatz, Gavin & Gagne 4 Process PC … Address Space February 20 Copyright 2018 Silberschatz, Gavin & Gagne 5 Process Control Block (PCB) Information associated with each process (also called task control block) • Process state – running, waiting, etc • Program counter – location of instruction to next execute • CPU registers – contents of all process- centric registers • CPU scheduling information- priorities, scheduling queue pointers • Memory-management information – memory allocated to the process • Accounting information – CPU used, clock time elapsed since start, time limits • I/O status information – I/O devices allocated to process, list of open files February 20 Copyright 2018 Silberschatz, Gavin & Gagne 6
    [Show full text]
  • NSWI 0138: Advanced Unix Programming
    NSWI 0138: Advanced Unix programming (c) 2011-2016 Vladim´ırKotal (c) 2009-2010 Jan Pechanec, Vladim´ırKotal SISAL MFF UK, Malostransk´en´am.25, 118 00 Praha 1 Charles University Czech Republic Vladim´ırKotal [email protected] March 10, 2016 1 Vladim´ırKotal NSWI 0138 (Advanced Unix programming) Contents 1 Overview 5 1.1 What is this lecture about? . .5 1.2 The lecture will cover... .5 1.3 A few notes on source code files . .6 2 Testing 6 2.1 Why?...........................................6 2.2 When ? . .6 2.3 Types of testing . .7 3 Debugging 8 3.1 Debuging in general . .8 3.2 Observing . .9 3.3 Helper tools . .9 3.3.1 ctags . .9 3.3.2 cscope . 10 3.3.3 OpenGrok . 11 3.3.4 Other tools . 11 3.4 Debugging data . 11 3.4.1 stabs . 11 3.4.2 DWARF . 12 3.4.3 CTF (Compact C Type Format) . 12 3.5 Resource leaks . 13 3.6 libumem . 13 3.6.1 How does libumem work . 14 3.6.2 Using libumem+mdb to find memory leaks . 14 3.6.3 How does ::findleaks work . 16 3.7 watchmalloc . 17 3.8 Call tracing . 18 3.9 Using /proc . 19 3.10 Debugging dynamic libraries . 20 3.11 Debuggers . 20 3.12 Symbol search and interposition . 20 3.13 dtrace . 21 4 Terminals 21 4.1 Terminal I/O Overview . 21 4.2 Terminal I/O Overview (cont.) . 22 4.3 Physical (Hardware) Terminal . 24 4.4 stty(1) command . 24 4.5 TTY Driver Connected To a Phy Terminal .
    [Show full text]
  • Fibers Without Scheduler
    Document number: P0876R5 Date: 2019-01-21 Author: Oliver Kowalke ([email protected]) Nat Goodspeed ([email protected]) Audience: SG1 fiber_context - fibers without scheduler Revision History . .1 abstract . .1 control transfer mechanism . .2 std::fiber_context as a first-class object . .3 encapsulating the stack . .3 invalidation at resumption . .4 problem: avoiding non-const global variables and undefined behaviour . .4 solution: avoiding non-const global variables and undefined behaviour . .6 inject function into suspended fiber . 10 passing data between fibers . 12 termination . 13 exceptions . 13 stack destruction . 14 std::fiber_context as building block for higher-level frameworks . 14 interaction with STL algorithms . 16 possible implementation strategies . 16 fiber switch on architectures with register window . 18 how fast is a fiber switch . 18 interaction with accelerators . 18 multi-threading environment . 18 acknowledgment . 19 API ................................................................ 20 33.7 Cooperative User-Mode Threads . 20 33.7.1 General . 20 33.7.2 Header <experimental/fiber_context> synopsis . 20 33.7.3 Class fiber_context . 20 33.7.4 Function unwind_fiber() . 25 33.7.5 Class unwind_exception . 25 references . 26 Revision History This document supersedes P0876R4. Changes since P0876R4: abstract This paper addresses concerns, questions and suggestions from the past meetings. The proposed API supersedes the former proposals N3985,5 P0099R1,7 P0534R3,8 P0876R09 and P0876R2.10 Because of name clashes with coroutine from coroutine TS, execution context from executor proposals and continuation used in the context of future::then(), the committee has indicated that fiber is preferable. However, given the foundational, low-level nature of this proposal, we choose fiber_context, leaving the term fiber for a higher-level facility built on top of this one.
    [Show full text]
  • O'reilly & Associates, Inc
    Java Threads, 2nd edition Scott Oaks & Henry Wong 2nd Edition January 1999 ISBN: 1-56592-418-5, 332 pages Revised and expanded to cover Java 2, Java Threads shows you how to take full advantage of Java's thread facilities: where to use threads to increase efficiency, how to use them effectively, and how to avoid common mistakes. It thoroughly covers the Thread and ThreadGroup classes, the Runnable interface, and the language's synchronized operator. The book pays special attention to threading issues with Swing, as well as problems like deadlock, race condition, and starvation to help you write code without hidden bugs. Table of Contents Preface 1 1. Introduction to Threading 5 Java Terms Thread Overview Why Threads? Summary 2. The Java Threading API 12 Threading Using the Thread Class Threading Using the Runnable Interface The Life Cycle of a Thread Thread Naming Thread Access More on Starting, Stopping, and Joining Summary 3. Synchronization Techniques 31 A Banking Example Reading Data Asynchronously A Class to Perform Synchronization The Synchronized Block Nested Locks Deadlock Return to the Banking Example Synchronizing Static Methods Summary 4. Wait and Notify 50 Back to Work (at the Bank) Wait and Notify wait(), notify(), and notifyAll() wait() and sleep() Thread Interruption Static Methods (Synchronization Details) Summary 5. Useful Examples of Java Thread Programming 64 Data Structures and Containers Simple Synchronization Examples A Network Server Class The AsyncInputStream Class Using TCPServer with AsyncInputStreams Summary 6. Java Thread Scheduling 87 An Overview of Thread Scheduling When Scheduling Is Important Scheduling with Thread Priorities Popular Scheduling Implementations Native Scheduling Support Other Thread-Scheduling Methods Summary Table of Contents (cont...) 7.
    [Show full text]