ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Operation System Concepts Ch.4 Thread

2021-04-25 19:34:20  阅读:172  来源: 互联网

标签:kernel thread System number threads user Ch.4 Operation Why


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.

标签:kernel,thread,System,number,threads,user,Ch.4,Operation,Why
来源: https://www.cnblogs.com/mollnn/p/14701629.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有