zoukankan      html  css  js  c++  java
  • Operation System Concepts Ch.4 Thread

    Overview

    Process creation is heavy-weight while thread creation is light-weight

    can simplify code, increase efficiency

    Benefits: responsiveness, sharing, economy, scalability

    multicore, multiprocessor, parallelism, concurrency

    Data parallelism: same data distributed across multicores, same operation on each

    Task parallelism: each thread performing unique operation on different cores

    Amdahl's Law

    Multithreading Models

    User/Kernel

    User threads: management by user-level threads library

    Kernel threads: support by kernel

    Kernel have a thread table for kernel threads, while Process have own thread table for user threads

    Why user thread? no kernel intervention, efficient

    Why not user thread? one blocked, all blocked

    Why kernel thread? can on different processors

    Why not kernel thread? slow

    Models

    Many-to-One (one block all block, can not parallel, few now)

    One-to-One (more concurrency, number restricted)

    Many-to-Many (sufficient)

    Two-Level (allow 1:1 and M:M)

    M:M for server, 1:1 for PC

    Thread Libraries

    Library: user space or kernel-level

    Pthreads: either as user-level or kernel level, a specification not implementation

    Implicit Threading

    creation and management of threads done by compilers

    thread pools: create a number of threads in a pool where they await work (faster, large number)

    Threading Issues

    fork() and exec()

    two version of fork(): copy all threads or copy one thread

    exec() replace all thread

    if exec() immediately after fork() then copy all is unnecessary

    Cancellation

    async: immediately

    deferred: allow target thread to periodically check if cancelled

    disabled: remains pending until enables it

    Signal Handling

    signals are used to notify a process that a event has occurred

    where should a signal be delivered for multi-threaded?

    all threads in a process share a same handler

    Thread-Local Storage

    each thread have its own data, across functions, similar to static data

    Why not use thread stack? life cycle reasons.

    Scheduler Activations

    How to maintain an appropriate number of kernel threads allocated to the app?

    Intermediate data structure between user and kernel threads: lightweight process (LWP), a virtual processor on which process can schedule user thread to run, each LWP attached to kernel thread

    Upcalls: from kernel to the upcall handler in the thread library

    When blocked, the attached LWP also blocks. The kernel makes an upcall and then allocates a new LWP to the application.

  • 相关阅读:
    Intellij IDEA调试功能使用总结
    193.数据库备份和恢复
    191.数据安全性控制
    192.数据完整性管理
    190.事务管理与并发控制
    189.存储过程和触发器
    云笔记项目-笔记列表弹出"分享移动删除"子菜单
    使用JavaMail发送邮件-从FTP读取图片并添加到邮件正文发送
    二进制学习
    云笔记项目-网页端debug功能学习
  • 原文地址:https://www.cnblogs.com/mollnn/p/14701629.html
Copyright © 2011-2022 走看看