An Introduction to Programming with C (介绍c编程).pdf
文本预览下载声明
An Introduction to Programming with C# Threads
Andrew D. Birrell
This paper provides an introduction to writing concurrent programs with “threads”. A
threads facility allows you to write programs with multiple simultaneous points of
execution, synchronizing through shared memory. The paper describes the basic thread
and synchronization primitives, then for each primitive provides a tutorial on how to use
it. The tutorial sections provide advice on the best ways to use the primitives, give
warnings about what can go wrong and offer hints about how to avoid these pitfalls. The
paper is aimed at experienced programmers who want to acquire practical expertise in
writing concurrent programs. The programming language used is C#, but most of the
tutorial applies equally well to other languages with thread support, such as Java.
Categories and Subject Descriptors: D.1.3 [Programming Techniques]: Concurrent
Programming; D.3.3 [Programming Languages]: Language Constructs and Features —
Concurrent programming structures; D.4.1 [Operating Systems]: Process Management
General Terms: Design, Languages, Performance
Additional Key Words and Phrases: Threads, Concurrency, Multi-processing,
Synchronization
CONTENTS
1. Introduction 1
2. Why use concurrency? 2
3. The design of a thread facility 3
4. Using Locks: accessing shared data 8
5. Using Wait and Pulse: scheduling shared resources 16
6. Using Threads: working in parallel 25
7. Using Interrupt: diverting the flow of control 31
8. Additional techniques 33
9. Advanced C# Features 36
10. Building your program 36
11. Concluding remarks 38
© Microsoft Corporation 2003.
Permission to copy in whole or part without payment of fee i
显示全部