Concurrent Programming on Windows

Paperback (Print)
Used and New from Other Sellers
Used and New from Other Sellers
from $16.18
Usually ships in 1-2 business days
(Save 73%)
Other sellers (Paperback)
  • All (11) from $16.18   
  • New (5) from $44.87   
  • Used (6) from $16.18   

Overview

“When you begin using multi-threading throughout an application, the importance of clean architecture and design is critical. . . . This places an emphasis on understanding not only the platform’s capabilities but also emerging best practices. Joe does a great job interspersing best practices alongside theory throughout his book.”

– From the Foreword by Craig Mundie, Chief Research and Strategy Officer, Microsoft Corporation

Author Joe Duffy has risen to the challenge of explaining how to write software that takes full advantage of concurrency and hardware parallelism. In Concurrent Programming on Windows, he explains how to design, implement, and maintain large-scale concurrent programs, primarily using C# and C++ for Windows.

Duffy aims to give application, system, and library developers the tools and techniques needed to write efficient, safe code for multicore processors. This is important not only for the kinds of problems where concurrency is inherent and easily exploitable—such as server applications, compute-intensive image manipulation, financial analysis, simulations, and AI algorithms—but also for problems that can be speeded up using parallelism but require more effort—such as math libraries, sort routines, report generation, XML manipulation, and stream processing algorithms.

Concurrent Programming on Windows has four major sections: The first introduces concurrency at a high level, followed by a section that focuses on the fundamental platform features, inner workings, and API details. Next, there is a section that describes common patterns, best practices, algorithms, and data structures that emerge while writing concurrent software. The final section covers many of the common system-wide architectural and process concerns of concurrent programming.

This is the only book you’ll need in order to learn the best practices and common patterns for programming with concurrency on Windows and .NET.

Read More Show Less

Product Details

  • ISBN-13: 9780321434821
  • Publisher: Addison-Wesley
  • Publication date: 11/12/2008
  • Series: Microsoft .NET Development Series
  • Edition description: New Edition
  • Pages: 1008
  • Product dimensions: 7.00 (w) x 8.90 (h) x 2.20 (d)

Meet the Author

Joe Duffy is the development lead, architect, and founder of the Parallel Extensions to the .NET Framework team at Microsoft. In addition to hacking code and managing a team of developers, he works on long-term vision and incubation efforts, such as language and type system support for concurrency safety. He previously worked on the Common Language Runtime team. Joe blogs regularly at www.bluebytesoftware.com/blog.

Read More Show Less

Read an Excerpt

I began writing this book towards the end of 2005. At the time, dual-core processors were becoming standard on the mainstream PC's that ordinary (non-programmer) consumers were buying, and a small number of people in industry had begun to make noise about the impending concurrency problem. (Herb Sutter's The Free Lunch is Over paper immediately comes to mind.) The problem people were worried about, of course, was that the software of the past was not written in a way that would allow it to naturally exploit that additional compute power. Contrast that with the never-ending increase in clock speeds. No more free lunch indeed.

It seemed to me that concurrency was going to be an important part of every software developer's job somewhere down the road and that a book like this would be important and useful. Just over two years later, the impact is beginning to ripple up from the operating system, through the libraries, and on up to applications themselves.

This was about the same time I had wrapped up prototyping a small side-project on which I had been burning the midnight oil for the previous six months: Parallel Language Integrated Query (PLINQ). The PLINQ project was a conduit for me to explore the intricacies of concurrency, multi-core, and specifically how parallelism might be used in real-world, everyday programs. I used it as a tool to figure out where the platform was lacking. This was in addition to spending my day job at Microsoft focused on software transactional memory (STM), a technology that in the intervening two years has become somewhat of an industry buzzword. Needless to say, I had become pretty entrenched in all topicsconcurrency. What better way to get entrenched even further than to write a book on the subject?

As I worked on all of these projects, and eventually PLINQ grew into Parallel Extensions to the .NET Framework, I was amazed at how few good books on Windows concurrency were available. I remember time and time again being astonished or amazed at some intricate and esoteric bit of concurrency-related information, jotting it down, and earmarking it for inclusion in this book. I only wished somebody had written it down before me, so that I didn't need to scour it from numerous sources: hallway conversations, long nights of pouring over Windows and CLR source code, and reading and rereading countless Microsoft employee blogs. But the best books on the topic dated back to the early '90s and, while still really good, focused too much on the mechanics and not on how to structure parallel programs, implement parallel algorithms, deal with concurrency hazards, and other important concepts. Everything else targeted academics and researchers, and not application, system, and library developers.

I set out to write a book that I'd have found fascinating and a useful way to shortcut all of the random bits of information I had to learn throughout. Although it took me a surprisingly long two-and-a-half years to finish this book (!), the state of the art has evolved slowly, and the state of good books on the topic hasn't changed much either. The result of my efforts, I hope, is a new book that is down-to-earth and useful, but still full of very deep technical information. It is for any Windows or .NET developer who believes that concurrency is going to be a fundamental requirement of all software somewhere down the road, as all industry trends seem to imply.

I look forward to kicking back and enjoying this book. And I sincerely hope you do too.Book Structure

I've structured the book into four major parts. The first, Concepts, introduces concurrency at a high level without going too deep into any one topic. The next part, Mechanisms, focuses squarely on the fundamental platform features, inner workings, and API details. After that, the part on Techniques describes common patterns, best practices, algorithms, and data structures that emerge while writing concurrent software. The fourth part, Systems, covers many of the systemwide architectural and process concerns that frequently arise. There is a progression here. Concepts is first because it develops a basic understanding of concurrency in general. Understanding the content in Techniques would be difficult without a solid understanding of the Mechanisms, and similarly, building real Systems would be impossible without understanding the rest. There is also a collection of Appendices at the end.Code Requirements

To run code found in this book, you'll need to download some free pieces of software:

  • Microsoft Windows SDK. This includes the Microsoft C++ compiler and relevant platform headers and libraries. The latest versions as of this writing are the Windows Vista and Server 2008 SDKs.
  • Microsoft .NET Framework SDK. This includes the Microsoft C# and Visual Basic compilers, and relevant framework libraries. The latest version as of this writing is the .NET Framework 3.5 SDK.

Both can be found on MSDN: http://msdn.microsoft.com/.

In addition, it's highly recommended that you consider using Visual Studio. This is not required—and in fact, much of the code in this book was written in emacs—but provides for a more seamless development and debugging experience. Visual Studio 2008 Express Edition can be downloaded for free, although it lacks many useful capabilities such as performance profiling.

Lastly, the Debugging Tools for Windows package—which includes the popular WINDBG debugging utility—might also come in handy, particularly if you don't have Visual Studio. It is freely downloadable from http://www.microsoft.com/. Similarly, the Sysinternals utilities available from http://technet.microsoft.com/sysinternals/ are quite useful for inspecting aspects of the Windows OS.

A companion website for the book will be available simultaneous with publication of the book.

Joe Duffy
June 2008

joe@bluebytesoftware.com

Read More Show Less

Table of Contents

Foreword xix

Preface xxiii

Acknowledgments xxvii

About the Author xxix

Part I: Concepts 1

Chapter 1: Introduction 3

Why Concurrency? 3

Program Architecture and Concurrency 6

Layers of Parallelism 8

Why Not Concurrency? 10

Where Are We? 11

Chapter 2: Synchronization and Time 13

Managing Program State 14

Synchronization: Kinds and Techniques 38

Where Are We? 73

Part II: Mechanisms 77

Chapter 3: Threads 79

Threading from 10,001 Feet 80

The Life and Death of Threads 89

Where Are We? 124

Chapter 4: Advanced Threads 127

Thread State 127

Inside Thread Creation and Termination 152

Thread Scheduling 154

Where Are We? 180

Chapter 5: Windows Kernel Synchronization 183

The Basics: Signaling and Waiting 184

Using the Kernel Objects 211

Where Are We? 251

Chapter 6: Data and Control Synchronization 253

Mutual Exclusion 255

Reader/Writer Locks (RWLs) 287

Condition Variables 304

Where Are We? 312

Chapter 7: Thread Pools 315

Thread Pools 101 316

Windows Thread Pools 323

CLR Thread Pool 364

Performance When Using the Thread Pools 391

Where Are We? 398

Chapter 8: Asynchronous Programming Models 399

Asynchronous Programming Model (APM) 400

Event-Based Asynchronous Pattern 421

Where Are We? 427

Chapter 9: Fibers 429

An Overview of Fibers 430

Using Fibers 435

Additional Fiber-Related Topics 445

Building a User-Mode Scheduler 453

Where Are We? 473

Part III: Techniques 475

Chapter 10: Memory Models and Lock Freedom 477

Memory Load and Store Reordering 478

Hardware Atomicity 486

Memory Consistency Models 506

Examples of Low-Lock Code 520

Where Are We? 541

Chapter 11: Concurrency Hazards 545

Correctness Hazards 546

Liveness Hazards 572

Where Are We? 609

Chapter 12: Parallel Containers 613

Fine-Grained Locking 616

Lock Free 632

Coordination Containers 640

Where Are We? 654

Chapter 13: Data and Task Parallelism 657

Data Parallelism 659

Task Parallelism 684

Message-Based Parallelism 719

Cross-Cutting Concerns 720

Where Are We? 732

Chapter 14: Performance and Scalability 735

Parallel Hardware Architecture 736

Speedup: Parallel vs. Sequential Code 756

Spin Waiting 767

Where Are We? 781

Part IV: Systems 783

Chapter 15: Input and Output 785

Overlapped I/O 786

I/O Cancellation 822

Where Are We? 826

Chapter 16: Graphical User Interfaces 829

GUI Threading Models 830

.NET Asynchronous GUI Features 837

Where Are We? 860

Part V: Appendices 863

Appendix A: Designing Reusable Libraries for Concurrent .NET Programs 865

The 20,000-Foot View 866

The Details 867

Appendix B: Parallel Extensions to .NET 887

Task Parallel Library 888

Parallel LINQ 910

Synchronization Primitives 915

Concurrent Collections 924

Index 931

Read More Show Less

Preface

I began writing this book towards the end of 2005. At the time, dual-core processors were becoming standard on the mainstream PC's that ordinary (non-programmer) consumers were buying, and a small number of people in industry had begun to make noise about the impending concurrency problem. (Herb Sutter's The Free Lunch is Over paper immediately comes to mind.) The problem people were worried about, of course, was that the software of the past was not written in a way that would allow it to naturally exploit that additional compute power. Contrast that with the never-ending increase in clock speeds. No more free lunch indeed.

It seemed to me that concurrency was going to be an important part of every software developer's job somewhere down the road and that a book like this would be important and useful. Just over two years later, the impact is beginning to ripple up from the operating system, through the libraries, and on up to applications themselves.

This was about the same time I had wrapped up prototyping a small side-project on which I had been burning the midnight oil for the previous six months: Parallel Language Integrated Query (PLINQ). The PLINQ project was a conduit for me to explore the intricacies of concurrency, multi-core, and specifically how parallelism might be used in real-world, everyday programs. I used it as a tool to figure out where the platform was lacking. This was in addition to spending my day job at Microsoft focused on software transactional memory (STM), a technology that in the intervening two years has become somewhat of an industry buzzword. Needless to say, I had become pretty entrenched in all topics concurrency. What better way to get entrenched even further than to write a book on the subject?

As I worked on all of these projects, and eventually PLINQ grew into Parallel Extensions to the .NET Framework, I was amazed at how few good books on Windows concurrency were available. I remember time and time again being astonished or amazed at some intricate and esoteric bit of concurrency-related information, jotting it down, and earmarking it for inclusion in this book. I only wished somebody had written it down before me, so that I didn't need to scour it from numerous sources: hallway conversations, long nights of pouring over Windows and CLR source code, and reading and rereading countless Microsoft employee blogs. But the best books on the topic dated back to the early '90s and, while still really good, focused too much on the mechanics and not on how to structure parallel programs, implement parallel algorithms, deal with concurrency hazards, and other important concepts. Everything else targeted academics and researchers, and not application, system, and library developers.

I set out to write a book that I'd have found fascinating and a useful way to shortcut all of the random bits of information I had to learn throughout. Although it took me a surprisingly long two-and-a-half years to finish this book (!), the state of the art has evolved slowly, and the state of good books on the topic hasn't changed much either. The result of my efforts, I hope, is a new book that is down-to-earth and useful, but still full of very deep technical information. It is for any Windows or .NET developer who believes that concurrency is going to be a fundamental requirement of all software somewhere down the road, as all industry trends seem to imply.

I look forward to kicking back and enjoying this book. And I sincerely hope you do too.

Book Structure

I've structured the book into four major parts. The first, Concepts, introduces concurrency at a high level without going too deep into any one topic. The next part, Mechanisms, focuses squarely on the fundamental platform features, inner workings, and API details. After that, the part on Techniques describes common patterns, best practices, algorithms, and data structures that emerge while writing concurrent software. The fourth part, Systems, covers many of the systemwide architectural and process concerns that frequently arise. There is a progression here. Concepts is first because it develops a basic understanding of concurrency in general. Understanding the content in Techniques would be difficult without a solid understanding of the Mechanisms, and similarly, building real Systems would be impossible without understanding the rest. There is also a collection of Appendices at the end.

Code Requirements

To run code found in this book, you'll need to download some free pieces of software:

  • Microsoft Windows SDK. This includes the Microsoft C++ compiler and relevant platform headers and libraries. The latest versions as of this writing are the Windows Vista and Server 2008 SDKs.
  • Microsoft .NET Framework SDK. This includes the Microsoft C# and Visual Basic compilers, and relevant framework libraries. The latest version as of this writing is the .NET Framework 3.5 SDK.

Both can be found on MSDN: http://msdn.microsoft.com/.

In addition, it's highly recommended that you consider using Visual Studio. This is not required--and in fact, much of the code in this book was written in emacs--but provides for a more seamless development and debugging experience. Visual Studio 2008 Express Edition can be downloaded for free, although it lacks many useful capabilities such as performance profiling.

Lastly, the Debugging Tools for Windows package--which includes the popular WINDBG debugging utility--might also come in handy, particularly if you don't have Visual Studio. It is freely downloadable from http://www.microsoft.com/. Similarly, the Sysinternals utilities available from http://technet.microsoft.com/sysinternals/ are quite useful for inspecting aspects of the Windows OS.

A companion website for the book will be available simultaneous with publication of the book.

Joe Duffy June 2008
joe@bluebytesoftware.com

Read More Show Less

Customer Reviews

Average Rating 5
( 1 )
Rating Distribution

5 Star

(1)

4 Star

(0)

3 Star

(0)

2 Star

(0)

1 Star

(0)

Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation

Reminder:

  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

 
Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously
Sort by: Showing 1 Customer Reviews
  • Anonymous

    Posted February 5, 2009

    No text was provided for this review.

Sort by: Showing 1 Customer Reviews

If you find inappropriate content, please report it to Barnes & Noble
Why is this product inappropriate?
Comments (optional)