




已阅读5页,还剩20页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
一入 Java 深似海 系列课程 - 第四期 第一节:POSIX Thread 小马哥 mercyblitz 一入 Java 深似海 系列课程 讲师信息 小马哥,Java 劝退师,Apache 和 Spring Cloud 等知名开源 架构成员。 微信:mercyblitz-1985 GitHub: 课件资源: lessons/ 博客:https:/mercyblitz.github.io/ 一入 Java 深似海 系列课程 小马哥书籍预售 Spring Boot 编程思想 - 核心篇 以 Spring Boot 2.0 为讨论的主线,讨论的范围将涵盖 Spring Boot 1.x 的所有版本,以及所关联的 Spring Framework 版本 场景分析:掌握技术选型 系统学习:拒绝浅尝辄止 重视规范:了解发展趋势 源码解读:理解设计思想 实战演练:巩固学习成果 主要议题 POSIX Thread 简介 POSIX Thread 基础 API POSIX Thread 同步 API 课程总结 下期预告 POSIX Thread 简介 POSIX Thread POSIX 简介 POSIX stands for Portable Operating System Interface for UNIX POSIX is thus not an implementation of UNIX but rather specifi cations of the APIs available for UNIX implementations. The standards in POSIX are specifi ed by the IEEE. POSIX Thread POSIX Thread 介绍 The POSIX thread libraries are a standards based thread API for C/C+. It allows one to spawn a new concurrent process fl ow. It is most effective on multi-processor or multi-core systems where the process fl ow can be scheduled to run on another processor thus gaining speed through parallel or distributed processing.Threads require less overhead than forking or spawning a new process because the system does not initialize a new system virtual memory space and environment for the process. While most effective on a multiprocessor system, gains are also found on uniprocessor systems which exploit latency in I/O and other system functions which may halt process execution. POSIX Thread POSIX Thread 介绍 POSIX Threads are described by three parts: Functions for runnning threads Functions for synchronizing threads Functions for scheduling threads POSIX Thread 线程基础 同进程中的线程 进程指令(Process instructions) 打开的文件描述(FD) 信号和信号处理(signals and signal handlers) 当前工作目录(current working directory) POSIX Thread 线程基础 线程特有的 线程ID(Thread ID) 寄存器集合、栈指针(set of registers, stack pointer) 局部变量栈和返回地址(stack for local variables, return addresses) POSIX Thread 线程基础 线程特有的 信号掩码(signal mask) 优先级(priority) 返回值(Return value: errno) POSIX Thread 基础 API POSIX Thread 基础 API 核心 API - 创建线程 pthread_create Java API - new Thread(Runnable) POSIX Thread 基础 API 核心 API - 线程属性(pthread_attr_t) pthread_attr_* 状态:是否可 JOIN,默认值 PTHREAD_CREATE_JOINABLE 调度策略:是否实时,默认值 范围:内核(PTHREAD_SCOPE_SYSTEM)、用户(PTHREAD_SCOPE_PROCESS) 栈:地址和大小 POSIX Thread 基础 API 核心 API - 线程执行结束 pthread_join Java API - Thread#join() POSIX Thread 基础 API 核心 API - 终止线程 等待函数执行完毕 void pthread_exit(void* value) Java API - Thread#exit()(非公开方法) int pthread_cancel(pthread_t thread) Java API - Thread#stop()(不推荐方法) POSIX Thread 同步 API POSIX Thread 同步 API 线程同步 三大原语(primitives) 互斥(Mutex) 条件变量(Condition variable) 屏障(Barriers) POSIX Thread 同步 API 互斥(Mutex) A POSIX Threads mutex is a lock with a sleep queue and not a spin lock. 类型:pthread_mutex_t 函数: pthread_mutex_init - used to create mutex attribute objects respectively. pthread_mutex_destroy - used to free a mutex object which is no longer needed. POSIX Thread 同步 API 互斥(Mutex) 函数(续): pthread_mutex_lock - is used by a thread to acquire a lock on the specifi ed mutex variable. If the mutex is already locked by another thread, this call will block the calling thread until the mutex is unlocked. pthread_mutex_trylock - will attempt to lock a mutex. However, if the mutex is already locked, the routine will return immediately with a busy error code. This routine may be useful in preventing deadlock conditions, as in a priority-inversion situation. POSIX Thread 同步 API 互斥(Mutex) 函数(续): pthread_mutex_unlock - will unlock a mutex if called by the owning thread. Calling this routine is required after a thread has completed its use of protected data if other threads are to acquire the mutex for their work with the protected data. An error will be returned if: If the mutex was already unlocked If the mutex is owned by another thread POSIX Thread 同步 API 条件变量(Condition variable) A condition variable lets a thread wait for something to happen in the future, and another thread to inform it that it has happened. 类型:pthread_cond_t PO
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024年河南省豫地科技集团有限公司招聘真题
- 林地转让协议书
- 《建筑施工安全检查标准》图解
- 石大学前儿童保育学课件6-1集体儿童膳食预防食物中毒
- 城市与乡村文化互鉴与融合-洞察阐释
- 重庆菜籽油生产线项目可行性研究报告(参考模板)
- 玩具与文体用品企业经营管理方案
- 2025至2030年中国电子五金制品行业投资前景及策略咨询报告
- 2025至2030年中国理石漆行业投资前景及策略咨询报告
- 2025至2030年中国牛外脊行业投资前景及策略咨询报告
- 2024届新高考数学热点冲刺复习“三新”背景下如何提高成绩+以《数列》为例浅谈教材使用
- 年国家开放大学电大远程教育考试题题库及答案
- 平口钳的结构与工艺设计
- 2020智慧电厂产业洞察白皮书
- 虚拟机快速恢复与迁移技术方案
- 项目重难点分析
- 某附属医院围手术期血糖规范管理成果申报
- 催化氢化催化剂
- 2023年上海市普通高中学业合格考试历史试题
- 精选最近九年北京高考数学(理)压轴题(含答案)
- 临床路径汇编(完整版)资料
评论
0/150
提交评论