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. | An Introduction to Programming with C Threads Andrew D. Birrell Revised May 2005 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 . Programming Techniques Concurrent Programming D . Programming Languages Language Constructs and Features Concurrent programming structures D . Operating Systems Process Management General Terms Design Languages Performance Additional Key Words and Phrases Threads Concurrency Multi-processing Synchronization CONTENTS 1 . 2 . Why use concurrency .2 3 The design of a thread facility 3 4. Using Locks accessing shared 5 . Using Wait and Pulse scheduling shared 6 . Using Threads working in 7 Using Interrupt diverting the flow of control 31 8 Additional techniques 33 9 . Advanced C 10 . Building your 11 Concluding remarks 38 Microsoft Corporation 2003 2005. Permission to copy in whole or part without payment of fee is granted for nonprofit educational and research purposes provided that all such whole or partial copies include the following a notice that such copying is by permission of Microsoft Corporation an acknowledgement of the author of the work and this copyright notice. Parts of this work are based on research report 35