Skip to Content
C语言核心技术(原书第2版)
book

C语言核心技术(原书第2版)

by Peter Prinz, Tony Crawford
August 2017
Intermediate to advanced
798 pages
17h 44m
Chinese
China Machine Press
Content preview from C语言核心技术(原书第2版)
233
第14章
多线程
C
程序中经常同时执行多项任务。例如,一个程序可能:
•
在执行程序过程中通过完成并行任务来提高性能。
•
在处理用户输入的同时,在后台进行耗时的数据通信和实时操作。
通过并行执行(
concurrent execution
)程序中的部分代码,可以实现不同任务同时进
行。特别是在多处理器系统(当然也包括多核处理器)上,程序通过并行机制更有效地
使用系统资源,其意义越来越重大。
C11
标准以前,
C
开发人员必须依赖操作系统或相应链接库来实现并行。
C11
标准发布以
后,使得
C
程序可便捷地实现并行。
C11
支持多线程执行(
multithreaded execution
)。多
线程指的是在一个程序进程中处理控制流的多路并行通道,它在所有操作系统上为运行
该程序提供了相同程度的并发性。为此,
C11
标准定义了一个相应的内存模型(
memory
model
),并且支持原子操作(
atomic operation
)。在
C11
标准下,对于多线程和原子操
作的支持是可选的。如果支持
C11
标准的实现版本定义了宏
_STDC_NO_THREADS_
和
_STDC_
NO_ATOMICS_
,则
表示该实现版本不支持多线程与原子操作。
你可能曾使用过针对
C
语言的
POSIX
线程扩展(简称
pthreads
),该扩展是根据
UNIX
可
移植操作系统接口标准(
POSIX
)——
IEEE 1003.1c
——实现多线程编程的链接库。如
果使用过该扩展,你会发现
C11
线程编程的接口在很多方面与
POSIX
标准类似。
14.1 线程
当启动一个程序时,操作系统创建一个进程,并在该进程中执行程序。一个进程包括一 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

算法精讲视频课程:24篇系列讲座

算法精讲视频课程:24篇系列讲座

罗伯特·塞奇威克, 凯文·韦恩(Kevin Wayne)

Publisher Resources

ISBN: 9787111562207