Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 990 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
990
Dung lượng
10,79 MB
Nội dung
7.com k77 www.e oks ==> ebo Craig Mundie, Chief Research andboo Strategy Officer, Microsoft free Foreword by � T T Concurrent Programming on Windows nrR Development Series Joe www.it-ebooks.info WWW.EBOOK777.COM Duffy free ebooks ==> www.ebook777.com Praise for Concurrent Programming on Windows "I have been fascinated with concurrency ever since I added threading support to the Common Language Runtime a decade ago That's also where I met Joe, who is a world expert on this topic These days, concurrency is a first-order concern for practically all developers Thank goodness for Joe's book It is a tour de force and I shall rely on it for many years to come." -Chris Brumme, Distinguished Engineer, Microsoft "I first met Joe when we were both working with the Microsoft CLR team At that time, we had several discussions about threading and it was apparent that he was as passionate about this subject as I was Later, Joe transitioned to Microsoft's Parallel Computing Platform team where a lot of his good ideas about threading could come to fruition Most threading and concurrency books that I have come across contain information that is incorrect and explains how to solve contrived problems that good architecture would never get you into in the first place Joe's book is one of the very few books that I respect on the matter, and this respect comes from knowing Joe's knowledge, experience, and his ability to explain concepts." -Jeffrey Richter, Wintellect "There are few areas in computing that are as important, or shrouded in mystery, as concurrency It's not simple, and Duffy doesn't claim to make it so-but armed with the right information and excellent advice, creating correct and highly scalable systems is at least possible Every self-respecting Windows developer should read this book." -Jonathan Skeet, Software Engineer, Clearswift "What I love about this book is that it is both comprehensive in its coverage of concurrency on the Windows platform, as well as very practical in its presen tation of techniques immediately applicable to real-world software devel opment Joe's book is a 'must have' resource for anyone building native or managed code Windows applications that leverage concurrency!" -Steve Teixeira, Product Unit Manager, Parallel Computing Platform, Microsoft Corporation www.it-ebooks.info WWW.EBOOK777.COM free ebooks ==> www.ebook777.com "This book is a fabulous compendium of both theoretical knowledge and practical guidance on writing effective concurrent applications Joe Duffy is not only a preeminent expert in the art of developing parallel applications for Windows, he's also a true student of the art of writing For this book, he has combined those two skill sets to create what deserves and is destined to be a long-standing classic in developers' hands everywhere II -Stephen Toub, Program Manager Lead, Parallel Computing Platform, Microsoft II As chip designers run out of ways to make the individual chip faster, they have moved towards adding parallel compute capacity instead Consumer PCs with multiple cores are now commonplace We are at an inflection point where improved performance will no longer come from faster chips but rather from our ability as software developers to exploit concurrency Understanding the concepts of concurrent programming and how to write concurrent code has therefore become a crucial part of writing successful software With Concurrent Programming on Windows, Joe Duffy has done a great job explaining concurrent concepts from the fundamentals through advanced techniques The detailed descriptions of algorithms and their interaction with the underlying hardware turn a complicated subject into something very approachable This book is the perfect companion to have at your side while writing concurrent software for Windows." -Jason Zander, General Manager, Visual Studio, Microsoft www.it-ebooks.info WWW.EBOOK777.COM free ebooks ==> www.ebook777.com Concurrent Programming on Windows www.it-ebooks.info WWW.EBOOK777.COM free ebooks ==> www.ebook777.com Microsoft NET Development Series John Montgomery, Series Advisor Don Box, Series Advisor Brad Abrams, Series Advisor The award-winning Microsoft NET Development Series was established in 2002 to provide professional developers with the most comprehensive and practical coverage of the latest NET technologies It is supported and developed by the leaders and experts of Microsoft development technologies, including Microsoft architects, MVPs, and leading industry luminaries Books in this series provide a core resource of information and understanding every developer needs to write effective applications Titles in the Series Brad Abrams, NET Framework Standard Library Annotated Reference Volume 1: Base Class Library and Extended Numerics Library, 978-0-321-15489-7 James S Miller and Susann Ragsdale, Brad Abrams and Tamara Abrams, NET Framework Standard Library Annotated Reference, Volume 2: Networking Library, Reflection Library, and XML Library, 978-0-321-19445-9 Christian Nagel, Enterprise Services with the NET Framework: Developing Distributed Business Solutions with NET Enterprise Services, 978-0-321-24673-8 Essential Windows Presentation Foundation (WPF), 978-0-321-37447-9 Chris Anderson, Bob Beauchemin and Dan Sullivan, A Developer's Guide to SQL Server 2005, 978-0-321-38218-4 Adam Calderon, Joel Rumerman, Advanced ASP.NET AJAX Server Controls: For NET Framework 3.5, 978-0-321-51444-8 Visual Studio Tools for Office: Using C# with Excel, Word, Outlook, and InfoPath, 978-0-321-33488-6 Eric Carter and Eric Lippert, Visual Studio Tools for Office: Using Visual Basic 2005 with Excel, Word, Outlook, and InfoPath, 978-0-321-41175-4 Eric Carter and Eric Lippert, Steve Cook, Gareth Jones, Stuart Kent, Alan Cameron Domain-Specific Development with Visual Studio DSL Tools, 978-0-321-39820-8 Wills, Framework Design Guidelines: Conventions, Idioms, and Patterns for Reusable NET Libraries, Second Edition, 978-0-321-54561-9 Krzysztof Cwalina and Brad Abrams, Concurrent Programming on Windows, 978-0-321-43482-1 Joe Duffy, T he Common Language Infrastructure Annotated Standard, 978-0-321-15493-4 Brian Noyes, Data Binding with Windows Forms 2.0: Programming Smart Client Data Applications with NET , 978-0-321-26892-1 Smart Client Deployment with ClickOnce: Deploying Windows Forms Applications with ClickOnce, 978-0-321-19769-6 Brian Noyes, Fritz Onion with Keith Brown, Essential ASPNET 2.0, 978-0-321-23770-5 Essential Windows Communication Foundation: For NET Framework 3.5,978-0-321-44006-8 Steve Resnick, Richard Crane, Chris Bowen, Scott Roberts and Hagen Green, Designing Forms for Microsoft Office InfoPath and Forms Services 2007, 978-0-321-41059-7 eXtreme NET: Introducing eXtreme Programming Techniques to NET Developers, 978-0-321-30363-9 Neil Roodyn, Chris Sells and Michael Weinhardt, Windows Forms 2.0 Programming, 978-0-321-26796-2 Essential Windows Workflow Foundation, 978-0-321-39983-0 Dharma Shukla and Bob Schmidt, Sam Guckenheimer and Juan J Perez, Software Engineering with Microsoft Visual Studio Team System, 978-0-321-27872-2 Guy Smith-Ferrier, NET Internationalization: T he Developer's Guide to Building Global Windows and Web Applications, 978-0-321-34138-9 Anders Hejlsberg, Mads Torgersen, Scott Wiltamuth, Will Stott and James Newkirk, Visual Studio Team System: Better Software Development for Agile Teams, 978-0-321-41850-0 T he C# Programming Language, T hird Edition, 978-0-321-56299-9 Peter Golde, ASPNET 2.0 Illustrated, 978-0-321-41834-0 Paul Yao and David Durant, NET Compact Framework Programming with C#, 978-0-321-17403-1 T he NET Developer's Guide to Directory Services Programming, 978-0-321-35017-6 Paul Yao and David Durant, NET Compact Framework Programming with Visual Basic NET , 978-0-321-17404-8 Alex Homer and Dave Sussman, Joe Kaplan and Ryan Dunn, Mark Michaelis, Essential C# 3.0: For NET Framework 3.5, 978-0-321-53392-0 For more information go to informit.com/msdotnetseries/ www.it-ebooks.info WWW.EBOOK777.COM free ebooks ==> www.ebook777.com • •• Concurrent Programming on Windows • �.� Joe Duffy Addison-Wesley Upper Saddle River, NJ • Boston New York • Toronto • Montreal Capetown • Sydney • Tokyo • • • Indianapolis London Singapore • • • San Francisco Munich • Paris Mexico City www.it-ebooks.info WWW.EBOOK777.COM • Madrid free ebooks ==> www.ebook777.com Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals The NET logo is either a registered trademark or trademark of Microsoft Corporation in the United States and/or other countries and is used under license from Microsoft The author and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions No liability is assumed for incidental or conse quential damages in connection with or arising out of the use of the information or programs contained herein The publisher offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales, which may include electronic versions and/or custom covers and content particular to your business, training goals, marketing focus, and branding interests For more information, please contact: U.s Corporate and Government Sales (800) 382-3419 corpsales@pearsontechgroup.com For sales outside the United States please contact: International Sales international@pearsoned.com Visit us on the Web: informit.com/ aw Library o/Congress Cataloging-in-Publication Data Duffy, Joe, 1980Concurrent programming on Windows / Joe Duffy p cm Includes bibliographical references and index ISBN 978-0-321-43482-1 (pbk : alk paper) Parallel programming (Computer science) Electronic data processing-Distributed processing Multitasking (Computer science) Microsoft Windows (Computer file) I Title QA76.642D84 2008 005.2'75- www.ebook777.com For Mom • & Dad www.it-ebooks.info WWW.EBOOK777.COM free ebooks ==> www.ebook777.com www.it-ebooks.info WWW.EBOOK777.COM free ebooks ==> www.ebook777.com Contents at a Glance Con ten ts Xl Foreword xix Preface xxiii Acknowledgmen ts XXVll About the Au thor xxix PART I Concepts 1 Introduction Synchronization and Time PART II Mechanisms 13 77 79 Threads Advanced Threads Windows Kernel Synchronization Data and Control Synchronization Thread Pools Asynchronous Programming Models Fibers PART III 12 183 25 315 399 429 Techniques 475 10 Memory Models and Lock Freedom 1 Concurrency Hazards 477 45 ix www.it-ebooks.info WWW.EBOOK777.COM m 945 free ebooks ==> www.ebook77I n7.co d ex Message loops See Message pumps Message passing, 71 -73 Message Passing Interface (MPI), 720 Message pumps GUI and COM, 95-1 98 overview of, 830-833 MFENCE (full fence), 2-5 m_head, 535, 537 Microprocessor architectures, 78-1 79 Microsoft kernel debuggers, 271 Microsoft SQL Server, 433 Microsoft Windows In ternals (Russinovich and Solomon), 45, 54 minF reeTh reads element, httpRunt ime, 384-385 Minimum threads CLR thread pool, 379-382 delays from low, 385-386 Vista thread pool, 344, 348, 353 MinProce s sors, Tas kManagerPoli cy, 903 Missed pulses, 597-601 Missed wake-ups, 597-601 MMCSS (multimedia class scheduler service), 67 Modal loop, GUIs, 98 Modeling, Mon itor, creating fences, Mon i tor Enter method avoiding blocking, 275-277 CLR locks, 272-273 ensuring thread always leaves monitor, 273-275 locking onAppDomain agile objects, 279 reliability and CLR monitors, 281 -283 using value types, 277-278 Monitor Exit method avoiding blocking, 275-277 CLR locks, 272-273 ensuring thread always leaves monitor, 273-275 using value types, 277-278 Monitors, CLR avoiding blocking, 275-276 exiting and entering, 272-275 implementing, 283-285 overview of, 272 reliability and, 281 -283 using value types, 277-278 Monitors, NET Framework, 68-70, 309-31 MPI (Message Passing Interface), 720 MSC (Mellor-Crummey-Scott) locks, 778-781 MSDN Magazil1e, 590 MsgWa i t ForMul t i p leObj ect s ( Ex) API kernel synchronization, 98-202 motivation for using, 833 waiting for managed code, 207 MTAs (multithreaded apartments), 575, 834-835 MTATh readAt t r ibute, 835 Mult i Loc kHe l pe r Enter, 578 Multimedia class scheduler service (MMCSS), 67 Mutants See Mutexes Mutexes, 1 -2 abandoned, 21 7-21 acquiring and releasing, 21 6-2 avoiding registering waits for, 376 care when using APCs with, creating a n d opening, 2-21 defined, 42 designing library locks, 874 example of semaphores and, 224-226 overview of, 1 -2 process shutdown and, 564, 568, 571 signaled / nonsignaled state transition, 86 Vista thread pool completion tasks, 350-351 mutexSecu rity argument, Mutual exclusion mechanisms avoiding deadlocks with, 576 causing deadlocks, 575 data synchronization See Critical sections, Win32; Locks, CLR Dekker ' s and Dijkstra's algorithm, 50-53 executing interlocked operations, 492-493 hardware CAS instructions, 55-58 implementing critical regions, 47-48 Lamport's bakery algorithm, 54-55 Peterson's algorithm, 53-54 strict alternation, 49-50 m_value class, 521 -527 MWMO - WAITALL value, 202 "Myths about the Mutual Exclusion", Peterson, 53 N NA (neutral apartments), 834-835 Natural scalability, of algorithms, 760-761 Nested parallelism, 757 www.it-ebooks.info WWW.EBOOK777.COM 946 www.ebook777.com free Iebo n d e oks ==> Nesting loops, data parallelism and, 677-678 NET Framework avoiding building locks, 873 creating fences, 98-1 , creating threads, 52-1 53 dictionary (hashtable), 626-631 event-based asynchronous pattern in, 426-427 legacy reader / writer lock, 300-304 memory models, 6-51 monitors, 309-3 slim reader / writer lock (3.5), 293-300 synchronization contexts, 853-854 terminating threads See Threads, termination methods timers, 373 using APM in, 41 8-4 NET Framework Asynchronous GUI asynchronous operations, 855-856 Bac kGroundWo r k e r package, 856-860 overview of, 837 synchronization contexts, 847-854 Windows Forms, 837-840 Windows Presentation Foundation, 840-846 NET Framework asynchronous I / O asynchronous device / file I / O, 81 7-81 asynchronous sockets I /O, 820 822 I / O cancellation, 823 overview of, 81 Neutral Apartments (NA), 834-835 new Singleton ( ) statement, 521 , 524 Nod e l n foArray, WCT, 596 Non - const pointer, 36-38 Non-Uniform Memory Access (NUMA) machines, 78-1 79 Nonatomic software, 22 Nonblocking programming See also Lockfree data structures ABA problem, 536-537 defined, 477 implementing custom nonblocking stack, 534-536 parallel containers and, Win32 singly linked lists, 538-540 Nonlinear pipelines, 71 Nonlocal transfer of control, in Windows, 84 Nonsignaled events, 67 Not Buffe red merge, PLINQ, NP-hard problems, parallelism, 71 _NT_T I B, 46-1 48 NULL value, C reateThread failure, 92 NUMA (Non-Uniform Memory Access) machines, 78-1 79 o Object header inflation, 284-285 Object headers, CLR objects, 283-285 Object invariants, 548 object state argument, TPL, 890 Objects, overlapped, 788-792 Obstruction freedom, 28-bit interlocked operations, 500-502 Online debugging symbols, 39 OpenEvent ( E x ) APls, 228-230 Open E X i sting method closing mutexes, 215-2 opening events, 230 opening existing semaphore, 221 Open Semaphore, 220-222 OpenThread, 95 OpenTh readWaitChains e s s ion, WCT, 595-596 Optimistic concurrency, 625-626 Order preservation, PLINQ, 4-91 Orderly shutdown, 569-570 Orphaned locks, 45, 561 -562 Orphaning, abandoned mutexes and, O S threads, 879 880 OutofMemoryExc eption, 43 Output dependence, 485-486 Overflow, stack, 40-1 45 Overla pped class, 369-370 CLR thread pool I / O completion ports, 369-371 Overlapped I /O See also Asynchronous I / O overlapped objects, 788-792 overview of, 786-788 Overtaking race, 654 Ownership asserting lock, 872 CLR thread pool and, 377 debugging CLR monitor ownership, 285-287 debugging legacy RWLs, 303-304 defined, 32 mutex, 1 -21 overview of, 33-34 Vista thread pool, 352-353 www.it-ebooks.info WWW.EBOOK777.COM m 947 free ebooks ==> www.ebook77I n7.co d ex p P / Invoking, 881 P (taking), semaphores, 42 Pack method, CLR thread pool, 370 PAGE_GUARD attribute, 34, 37 Parallel class, TPL, 904-908 Parallel containers, 61 3-655 approaches to, 4-6 coordination containers, 640-650 fine-grained locking, 61 6-632 lock-free data structures, 632-640 phased computations with barriers, 650-654 sequential containers vs., 3-61 Parallel execution cancellation, 729-731 concurrent exceptions, 721 -729 data parallelism See data parallelism message-based parallelism, 71 9-720 overview of, 657-659 task parallelism See Task parallelism Parallel extensions to NET, 887-930 concurrent collections, 924-929 further reading, 930 overview of, 887-888 parallel LINQ, 0-91 synchronization primitives See Synchronization primitives TPL See TPL (task parallel library) Parallel hardware architecture, 736-756 cache coherence, 742-750 cache layouts, 740-742 locality, 750-751 memory hierarchy, 739 overview of, 736 profiling in Visual Studio, 754-756 sharing access to locations, 751 -754 SMp, CMP, and HT, 736-738 superscalar execution, 738-739 UMA vs NUMA, 740 Parallel LINQ See PLINQ (Parallel LINQ) Parallel merge-sort, 681 -684 Parallel quick-sort, 681 Parallel traversal, 61 Paralle l E n umerable class, PLINQ, 91 0-9 Parallelism deciding to igo paralleli, 756-758 defined, 80 designing reusable libraries, 866-867 layers of, 8-1 measuring improvement due to, 758 overview of, structured, 70-71 Pa ramet e r i zedThreadStart, 99 Parents, task parallel library, 895-897 Partitioning, P E (portable executable) image, -1 32 peb ( ! ) command, 46 PEB (process environment block), within TEB, 45 PeekMe s s age, 98-200 Performance AmdahIfs Law, 762-764 critical paths, 764-765 deciding to igo paralleli, 756-758 designing reusable libraries, 881 -884 garbage collection and scalability, 766-767 Gustafsonis Law, 764 interlocked operations, 493, 505-506 load imbalances and, 765-766 measuring improvement due to parallelism, 758 measuring speedups and efficiency, 760-762 Mellor-Crummey-Scott (MSC) locks, 778-781 natural scalability vs speedups, 760-761 overview of, 735-736 parallel hardware architecture See Parallel hardware architecture ReaderWriterLockSlim, 299 recursive lock acquires, 872 speedups and efficiencies and, 756 spin-only locks, 772-778 spin waiting and, 766-772 tuning quantum settings, 63 types of speedups, 758-760 Performance counters, querying thread state, 56-1 57 Periodic polling, 730 Persistent threads, Vista thread pool, 352-353 Pervasive concurrency, 865 Peterson's algorithm, 53-54 Phased computations with barriers, 650-654 Pi-calculus, 72 Pipelines defined, 541 generalized data structure, 71 2-71 www.it-ebooks.info WWW.EBOOK777.COM 948 ==> www.ebook777.com free I ebo n d ex oks Pipelines, contin ued load balanced, 71 6-71 Processes assigning CPU affinity to, 71 -1 75 overview of, 709-71 pipelining output o f futures o r promises, 698-702 PLINQ (Parallel LINQ) buffering and merging, 2-91 defined, 887 order preservation, 4-9 overview of, 0-91 Pointer size values, store atomicity and, 487 Polling asynchronous I / O completion, 798-800 canceling periodic, 730 Pollution, thread, 352, 377 Portable executable (PE) image, -1 32 Postconditions, as invariants, 548 Preconditions, as invariants, 547 Predictability, GUI, 836 Predictability, of responsive GUls, 836 Preemptive scheduling, 83, 54-1 55 Pre render event, ASP.NET, 421 Priorities custom thread pool with, 387-391 lock reliability and, 878 quantum adjustments and, 64-1 67 thread scheduling, 59-1 63 Priority boosts, 84, 232-234 Priority class, 59-1 60 Priority inheritance, 609 Priority inversion, 608-609, 0, 878 Priority level, 59 Priori ty, Thread class, 60 PriorityC l a s s, Proc e s s , 59 PriorityLevel, Proc e s s T h read, 60-1 61 Private state, shared state vs., 5-1 Privatization, 5-1 6, 33 ProbeForSt a c kSpace method, 45 ProbeF orSuff i c i e ntStack, 44, 49 Probes, stack, 43-1 45 Process affinity masks, CPU affinity, 73-1 74 Proc e s s class, 59, 75 Process environment block (PEB), 45 Process exit, threads, 1 3-1 Windows vs UNIX, 80-81 Proce s s Exit event, CLR, 569-570 ProcessorAffin ity, CPU affinity, 75 Processors concurrency in modern, creating fences at level of, 2-51 relationship between fibers, threads and, 438 Proc e s sPriorityC l a s s, 59 Proces sTh read class, 98, 60-1 61 Producer / consumer containers, Producer / consumer relationship, Process isolation, Process shutdown, locks and, 561 -571 managed code, 568 managed code and, 569-571 overview of, 561 -563 Win32: weakening and termination, 563-568 641 -642 Profilers, thread suspension in, 70 Program order, 480-484 Programming Windows (Petzold), 98 Programs, naturally scalable, Progress reporting, 425-426 Progre s sChangedEventHandler, 426 Promise style future, 900 Promises building dataflow systems, 693-695 pipelining output of, 698-702 Properties, ReaderWriterLockSlim, 295 Pseudo-handles, C reate Thread, 94-95 PTEB structure, 46 Publication, data ownership and, 33 Pulse NET Framework monitors, missed wake-ups, 598-601 two-step dance problems, 608 PulseAll NET Framework monitors, missed wake-ups, 598-601 two-step dance problems, 608 Pulse Event API, 231 Pulsing, NET Framework monitors, Pump messages, G U I a n d COM, 95-204 CoWa itForMu ltipleHandles API, 202-203 deciding when to pump messages, 203-204 MsgWa itForMult ipleObj ect s ( E x ) , 98-201 overview of, 95-1 98 Q Quantums, 83, 63-1 67 QueueUserWorkItem APM, 402-403 CLR thread pool, 371 www.it-ebooks.info WWW.EBOOK777.COM m 949 free ebooks ==> www.ebook77I n7.co d ex legacy thread pool, 354-356, 363 Th readPool class, 364-366 QueueWork functions, user-mode scheduler, 46�64 R Race conditions (data races), 546-555 benign, 553-555 composite actions and, 550-553 concurrency causing, eliminating with critical regions, 40 famous bugs due to, inconsistent synchronization and, 26, 549-550 invariants and, 548 in library code, 874-875 overview of, 546-549 patterns of critical region usage, 43-45 reasons for, 26-27 two-step dance problems due to, 607-608 Radix sort, algorithms, 681 Random access, linked lists, 621 Randomized backoff, 602-603 RCWs (runtime callable wrappers), 575 Reactive systems, 61 Read-only synchronization, 881 -882 Read / read hazards, 28, 34 Read / write hazards, 28 _ReadBarrier, 529 Reader/ writer locks See RWLs (reader / writer locks) Reade rWriterLock as legacy version, 300-304 motivating development of new lock, 299-300 overview of, 293-294 for read-only synchronization, 881 -882 reliability limitation, 298 Readerwrit e r LockSlim creating fences using, motivation for, 299-300 overview of, 293-294 process shutdown, 565 recursive acquires, 297-298 reliability limitation, 298-299 three modes of, 294-295 upgrading, 296-297 Read F i le, 792 readonly fields, single assignment, 35-36 readonly keyword, single assignment, 35 Ready thread state, 55 Recursion avoiding lock, 872 detecting in spin waiting, 773-775, 777 reentrancy and, 555-558 rules controlling, 558 task parallelism and, 702-709 Recursive acquires avoiding lock, 872 example of, 557-558 mutex support for, 21 overview of, 556-557 ReaderWriterLockSl im, 297-298 SRWLs non-support for, 292-293 using, 558-561 Recursive algorithms, 558-559 Recursive locks, 556 Recurs iveReadCount, ReaderWrit e r LockSl im, 295 Recurs iveUpgradeCount, ReaderWrit e r Loc kSl im, 295 Recurs iveWriteCount, ReaderWriterLockSl im, 295 Reduction, in data parallelism, 678-681 Reentrancy caused by pumping, 203 concurrency causing, 1 lock reliability and, 877-878 overview of, 555-556 system introduced, 559-561 Registered waits CLR thread pool, 374-377 legacy Win32 thread pool, 360-363 thread pools and, 322-323 Vista thread pool, 336-341 Registe redWai tHand le, CLR, 376 RegisterWaitForSingleObj e c t building user-mode scheduler, 466-467 CLR thread pool, 375 legacy thread pool, 360-361 Relative priority, individual threads, 59 Release fence, Release-followed-by-acquire-fence hazard, 5 releas eCount argument, 224 Release Lock, legacy RWLs, 301 ReleaseMutex, 5-21 ReleaseMutexWh enCallbac kReturns, 350 ReleaseSemapho re, 223-224 www.it-ebooks.info WWW.EBOOK777.COM 950 ==> www.ebook777.com free I ebo n d ex oks ReleaseSemapho reWhenCa llbac kRet u r n s , 351 ReleaseSRwLo c k E x c l u s ive, 290, 293 ReleaseSRWLo c k S h a red, 290, 293 Reliability designing library locks, 875-879 designing reusable libraries, 875-879 lock freedom and, 51 9-520 Remove, dictionary, 631 Rendezvous methods, asynchronous I / O APC callback, 806-808 event handler, 802-805 I / O completion ports, 808-8 overview of, 792, 796 poIling, 798-800 synchronous, 797-798 wait APls, 800-802 Rendezvous patterns, ATM, 403-405 Reserve size, threads creating stack overflow, 40-1 45 overview of, 30-1 33 stack memory layout, 38 ReSet Event, 230 _reset st koflw, 43 Responsiveness, GUI, 834-836 Restore Loc k, legacy RWls, 301 Res ume, Thread class, 40 Res umeThread, 91 ResumeThreat, 69 ret i rement algorit hm, 378-379 Rude shutdowns, 563 Rude thread aborts, 1 R u n method, 831 RunCla s s Constructor, 877-878 Running state, threads, 55, 58-1 59 Runtime callable wrappers (RCWs), 575 Runtime, fibers and ClR, 450-453 RuntimeHelpers ProbeForSuffic ientSt a c k, 44, 49 Runt imeHelpers RunCla s s Con st ructor, 877-878 RWls (reader / writer locks), 287-304 NET Framework legacy, 300-304 NET Framework slim, 293-300 defined, 28 defining, 254-255 overview of, 287-289 read-only synchronization using, 881 -882 Windows Vista SRWl, 288, 289-293 SafeHa ndles, 90 Scalability asynchronous I / O and, 787-788 designing reusable libraries for, 881-884 garbage collection and, 766-767 of parallel algorithms, 666 speedups vs natural, 760-761 Scalable access, of parallel containers, Scans, a n d data parallelism, 681 Schedules, thread, 878-879 Scheduling, 879-881 See also Thread scheduler, Windows; Thread scheduling Search algorithms, 71 8-71 9, 730 Security creating threads in NET, 99 creating threads in Win32, 90 using kernel objects, 88 SEH (structured exception handling), 04-1 06, 721 Self-replication, TPL, 909-9 Semaphores, 21 9-226 creating and opening, 220-222 designing library locks, 874 mutex / semaphore example, 224-226 overview of, 42, 21 9-220 signaled / nonsignaled state transition, 86 taking and releasing, 223-224 Vista thread pool completion tasks, 351 waiting and, 85 SemaphoreS lim, 920-921 Sense-reversing barriers, 650 Sentinel nodes, FIFO queues, 7-61 Sequential programming, 727-728 Serializability, 30 Serializable history, 25 Serialized threads, 25 Servers, garbage collection, 766-767 SetCrit ica lSectionSpinCount, 264-265 Set Data, TlS, 23 Set E r rorMode, 05 SetEvent, 230 SetMaxTh reads, Vista, 381 SetPriorityC l a s s , 59 SetProces sAffin ityMa s k, CPU affinity, 73-1 75 SetTh readAff i n i tyMa s k, CPU affinity, 74 SetTh readContext, www.it-ebooks.info WWW.EBOOK777.COM m 95 free ebooks ==> www.ebook77I n7.co d ex SetTh readpoolCa llbackRun Long, Vista, 349-350 SetTh read PoolMa ximum, legac� 363 SetTh readPoolMaximum, Vista, 344, 348, 353 SetThreadPoolMin imum, Vista, 344-345, 348, 353 SetThreadpoolTime r, Vista, 330-333 SetTh read poolWa it, Vista, 337-338, 340 SetTh readPriority, 60, 62, 352 SetTh readPriorityBoost, 65 SetTh readStac kGua rantee, 34-1 35, 36-1 37, 42 SetWaitableTime r, 236-237 S F ENCE (store fence), Shallow immutable objects, 34 Shared mode, ReaderWriterLoc kSl im, 294-295 Shared resources, among threads, 80-81 Shared state, 4-1 SharedReaderLock method, 300 Sha redWriterLock method, 300 Shutdown, building VMS, 470-472 Shutdown method, 470-471 Signaled events, 67 Signaled, vs nonsignaled kernel objects, 84-1 85 Signa lObj ectAndWa it blocking queue data structure with auto reset, 244-248 blocking queue data structure with events, 243-244 overview of, 241 -243 SimpleAsy n c R e s u lt class, APM, 3-4 Simultaneous multilock acquisition, 578-581 Single assignment, 34-38 Single threaded apartments See STAs (single threaded apartments) Singleton class, 521-523 64-bit Values, 499-500 Sleep API, 68 SleepCondit ionVa riableCS, 305-306 SleepCondit ionVariableSRW, 305-306 SleepEx API, 68 Sleeping condition variables and, 305-307 thread scheduling and, 67-1 68 Slim reader/ writer locks See SRWLs (slim reader / writer locks) SLIST_E NTRY data structure, 538-540 SLists (singly linked lists), 538-540 Soc ket class, APM, Sockets asynchronous sockets I / O in NET, 820-822 asynchronous sockets I / O in Win32, 4-8 Software interrupts, 84-85 some Lock, 598-601 Sort key, simultaneous multilock acquisition, 579-581 Sorting, 681-684 SOS debugging extensions, 285-287, 386-387 SoundPlayer, System d l l assembly, 427 Speculative search algorithms, 71 Speedup Amdahlis Law, 762-764 critical paths, 764-765 deciding to igo parallel!, 756-758 garbage collection and scalability, 766-767 Gustafsonis Law, 764 load imbalances and, 765-766 measuring, 758, 761 -762 natural scalability vs., 760-761 overview of, 756 types of, 758-760 Spin locks building, 921 -923 difficulty of implementing, 769 Mellor-Crummey-Scott, 778-781 for performance scalability, 873, 883 on Windows, 769-772 Spin-only locks, 772-778 Spin waiting avoiding blocking in CLR locks, 276-277 avoiding blocking in critical sections, 264-266 avoiding hand coding, 882 defining, 63-64 Mellor-Crummey-Scott (MSC) locks, 778-781 overview of, 767-769 spin-only locks and, 772-778 SRWLs, 290 Windows OSs and , 769-772 Spin Lock, 921 -923 SpinWait, 923-924 Spurious wake-ups, 1 -3 2, 598 SQL Server, fiber-based VMS, 86-87 SqlCommand type, APM, SRWLOCK, 290-292 SRWLoc k, 565-567 www.it-ebooks.info WWW.EBOOK777.COM 952 ==> www.ebook777.com free I ebo n d ex oks SRWLs (slim reader / writer locks) NET Framework, 293-300 immutability, 34-38 isolation, -34 integration with Windows Vista condition variables, 304-309 Windows Vista, 288, 289-293 SSA (static single assignment), 34-38 Stack limit, 33, 35-1 38 Stack memory layout, 33-1 40 example of, 35-1 38 guaranteeing committed guard space, 34-1 35 overview of, 33-1 34 stack traces, 38-1 40 Stack space, 33, 35-1 38 / STACK switch, 32 Stack traces, 38-1 40 s t a c k a lloc keyword, StackBase field, TEB, 47, 49 StackLimit field, TEB, 47, 49 Stac kOve rflowE x c e pt ion, 42 Iinearizability, 30-31 overview of, 4-1 Stacks ABA problem and, 536-537 creating new fibers, 436 implementing custom nonblocking, 534-536 overflow, 40-1 45 overview of, 82-83 reservation and commit sizes, 30-1 33 user-mode, 27-1 30 StackTrace class, 40 Stale read, 28 Stampedes, 605-606 Standby thread state, 55-1 56 START command, CPU affinity, 75 Start method, Th read class, 99 Sta rtNew methods, TPL, 890 StartThreadpoolIo function, Vista, 335-336 Starvation, 608-609, 878 STAs (single threaded apartments) deadlocks and, 574-575 overview of, 833-836 system introduced reentrancy and, 560-561 State, 4-38 atomicity, 29-30 broken invariants and invalid states, 20-21 in concurrent programs, 6-8 dependency, -62 fiber execution and, 430-431 general approaches to, identifying shared vs private, 5-19 serializability, 30 simple data race, 22-29 state machines and time, 9-20 thread See Thread state STAThreadAttribute, 835 Static decomposition continuous iterations and, 663 data parallelism and, 662-663 flaws in, 666 stat i c methods, Bloc k i n gCollection < T >, 927-928 Static single assignment (SSA), 34-38 Static TLS, 1 8, 20-1 22 static variables, 867-868 S TA TUS_GUARD_PAGE _VIOLA nON exception, 34 std : : i t e rator objects (C++), 672 stopped state, threads, 58 Store-after-Ioad dependence, 486 Store-after-store dependence, 485-486 Store atomicity, 487-492 Store fence ( SF ENCE ) , Stores NET Framework memory models, 6-51 o f 64-bit values, 499-500 atomic, 487-492, 499-500 hardware memory models and, Stream class, APM, Strict alternation Dekker's algorithm vs., 50-51 failure of in modern processors, 58-59 overview of, 49-50 Striped iterations, 667-669 Striping, 4-61 st rtok function, 96 Structured exception handling (SEH), 04-1 06, 721 Structured fork / join, 687 Structured parallelism, 70-71 Structured tasks, 896 Sub linear speedups, 758-760 Submi tTh readpoolWork API, Vista, 326-330 Superlinear speedups, 719, 758-760 S u s pend, T h read class, 40 S u s pended state, threads, 58-1 59 S u s pendTh reat, 69 www.it-ebooks.info WWW.EBOOK777.COM m 953 free ebooks ==> www.ebook77I n7.co dex Suspension, thread overview of, 91 stack trace and, 40 using in scheduling, 68-1 70 Swallowing exceptions, CLR, 05 Swit chToF iber, 440-44 , 443-445, 466 Switc hToThread API, 68 Sychronizes-with mechanism, 509-5 Synchronization inconsistent, 549-550 lock free vs lock-based algorithm and, never using thread suspension for, 70 synchronization contexts in NET, 853-854 synchronization contexts in Windows, 847-853 torn reads from flawed, 490 two-phase locking protocols, 767-769 Vista thread pool, 341 -342 Windows kernel See Kernel synchronization Synchronization and time, 3-75 control See Control synchronization data Sec Data synchronization managing program state See State overview of, 3-1 4, 38-40 Synchronization burden, 7-8 Synchronization primitives, 91 5-924 Countdown Event, 5-9 ISupportsCancelation, Lazylnit, 7-91 ManualResetEventSlim, 91 9-920 SemaphoreSl im, 920-921 SpinLock, 921 -923 SpinWa it, 923-924 Syn c h ronizat ionContext, 830, 837, 847-854 Synchronous aborts, 09, 1 Synchronous completion method, 797-798 Synchronous I / O, asynchronous I / O vs., 795 Synchronous I / O cancellation, 823, 824-825 Sync Lock, 607 Synclock keyword, 274, 277-278 System affinity mask, 72-1 73 System introduced reentrancy, 559 System registry key, 63 T ta rget Lock, 592 Task parallel library See TPL (task parallel library) Task parallelism, 684-71 dataflow parallelism, 689 defined, 658 fork/ join parallelism, 685-688 futures used t o build dataflow systems, 689-692 generalized pipeline data structure, 71 2-71 load balanced pipelines, 6-71 overview of, 684-685 pipelines, 709-71 pipelining output o f futures o r promises, 698-702 promises, 693-695 recursion, 702-709 resolving events to avoid blocking, 695-698 search algorithms and, 71 8-71 TaskC reat ionOpt ion s enum, 891 Ta s kMa nagerPolicy, TPL, 902-904 Ta s kMa nagers, TPL defined, 890 overview of, 902-904 TATAS locks, 778 Taxonomy concurrent program structure, 6-8 parallelism, TEB address, TEB (thread environment block) checking available stack space, 48-1 50 as internal data structure, 45-1 46 printing out information, 46 programmatically accessing, 46-1 48 stack memory layout, 35-1 38 thread creation details, 52 thread scheduling and, 881 thread state and, 27 Temporary boosting, 64-1 67 Terminated thread state, 56 TerminatePro c e s s API shutting down thread with brute force, 03 terminating process with, 563 terminating threads in Win32, 1 Windows Vista shutdown, 564 TerminateThread API abrupt termination with, 1 3-1 4, 53-1 54 overview of, 07-1 09 specifying return code at termination, 94 Termination, thread See Threads, termination methods Testing, wait condition inside locks, 878-879 www.it-ebooks.info WWW.EBOOK777.COM 954 ==> www.ebook777.com free I ebo n d ex oks The Banker's Algorithm, 577-581 Thin lock, 284 Third party in-process add-ins, 563 Third party locks, 873 Thread affinity defined, 87 designing reusable libraries, 866 fibers and, 433, 447-449 fibers and CLR, 452-453 Thread blocks See Blocks, thread Thread class, 98-1 , 32, 60 Thread coordination, 60-73 control synchronization and, 60-62 events, 66-68 message passing, 71 -73 monitors and condition variables, 68-70 state dependence among threads, 61 -62 structured parallelism, 70-71 waiting for something to happen, 63-66 Thread environment block See TEB (thread environment block) Thread information block (TIB), 45 Thread injection, 378-379 Thread local storage See TLS (thread local storage) Thread management legacy Win32 thread pool, 363-364 Vista thread pool, 347-350 Thread management, CLR thread pool, 377-386 deadlocks from low maximum, 382-385 delays from low minimum, 385-386 minimum and maximum threads, 379-382 thread injection and ret i rement a lgorit hm, Thread safety, 662 Thread scheduler, Windows advantages of fibers, 432 blocks and, 83-84 CPU affinity, 70-1 79 defined, 81-82 disadvantages of fibers, 433-434 functions of, 83 ideal processor, 79-1 80 priority and quantum adjustments, 64-1 67 priority based, 55 programmatically creating threads, 89 Thread scheduling, 54-1 80 advantages of fibers, 432 CPU affinity, 70-1 79 disadvantages of fibers, 433-434 ideal processor, 79-1 80 multimedia scheduler, 67 overview of, 54-1 55 priorities, 59-1 63 priority and quantum adjustments, 64-1 67 quantums, 63-1 64 sleeping and yielding, 67-1 68 suspension, 68-1 70 thread states, 55-1 59 Thread start routine, 89-90, 03 Thread state, 27-1 45 defined, 58 stack memory layout, 33-1 40 stack overflow, 40-1 45 stack reservation and commit sizes, 30-1 33 thread scheduling and, 55-1 59 I / O callbacks, 31 9-321 introduction to, 6-31 legacy Win32 See Win32 legacy thread pool overview of, 31 5-31 performance improvements of, 391 -397 registered waits, 322-323 timers, 321 -322 user-mode thread stacks, 27-1 30 ThreadAbort E x c e pt ion, 04 Threading models, CUI overview of, 830-833 single threaded apartments (STAs), 833-836 ThreadlnterruptedExcept ion, 208 Thread J oin, 00-1 , 885 Th read MemoryBa r r i e r, ! threadpool SOS extension command, 386-387 ThreadPriority, T a s kManagerPolicy, 903 UMS scheduler vs., 454 using explicit threading vs., 88 Windows Vista See Windows Vista thread pool work callbacks, writing own, 8-31 Threads, 79-1 25 asynchronous I / O cancellation for any, 825-826 asynchronous I / O cancellation for current, 823-824 CLR, 85-87 378-379 Thread pools, 31 5-398 CLR See CLR thread pool www.it-ebooks.info WWW.EBOOK777.COM m 955 free ebooks ==> www.ebook77I n7.co d ex contexts, -1 52 converting into fibers, 438-439 creating, 52-1 53 creating and deleting in Vista thread pool, 347-350 designing reusable libraries, 879-881 determining whether fibers are, 439-440 D L LMa in function, 1 5-1 explicit threading and alternatives, 87-88 fibers vs., 430-431 internal data structures, 45-1 51 local storage, 1 7-1 24 marshaling exceptions across, 721 -724 overview of, 79-81 programmatically creating, 89-90 programmatically creating in C programs, 96-98 programmatically creating in NET Framework, 98-1 01 programmatically creating in Win32, 90-96 routines, user-mode scheduler, 459-460 scheduling, 54-1 80 state See Thread state synchronous I / O cancellation for, 824-825 terminating, 53-1 54 Windows, 81-85 Threads, termination methods, 01 - 1 defined, 83 details of, 53-1 54 Exi tThread and TerminateThread, 07-1 09 overview of, 1 - 03 process exit, 1 3-1 returning from thread start routine, 03 thread aborts for managed code, 09-1 unhand led exceptions, 03-1 06 Thread Sleep API, 67-1 68, 882-883, 885 ThreadState property, 57 ThreadStaticAtt ribute type, TLS, -1 22 Thread volat ileRead method, ThreadWorkRout ine method, building VMS, 459-460 Thresholds, stopping parallel recursion, 706 TIB (thread information block), 45 TimeBeginPe riod API, 68 TimeEndPeriod API, 68 Timeouts NET Framework monitors, 309-31 c a l l i n g AsyncWai tHandles' Wai tOne, 407-41 condition variables, 306 detecting deadlocks, 594 Timer class, 371 -374 Timer class, CLR thread pool, 372-374 Timer queue, 356-359 TimerC a l l b a c k, CLR thread pool, 372 Timers See also Waitable timers CLR thread pool, 371 -374 legacy Win32 thread pool, 356-359 overview of, 321 -322 Vista thread pool, 330-334 Timeslice, 83 See also Preemptive scheduling TimeSpan value, WaitHandle class, 206 Timing, and concurrent programs, 24-29 TLS (thread local storage), 1 7-1 24 accessing through NET Framework, 880 creating threads in C programs, 96 fiber local storage vs., 445-447 managed code, -1 24 overview of, 1 Win32, 1 8-121 T l sAlloc API, 1 8-1 T l s F ree function, 1 Tl sGetVa lue API, 1 8-1 T LS_OUT_OF _INDEXES errors, 1 8-1 TlsSetVa l u e API, 1 8-1 Torn reads, 487-490, 491 -492 TPL (task parallel library), 888-9 cancellation, 897 continuations, 900-902 defined, 887 futures, 898-900 overview of, 888-893 parents and children, 895-897 putting it all together, 904-909 self-replication, 909-9 task managers, 902-904 unhandled exceptions, 893-895 TP_TIMER objects, 330-331 TP_WORK objects, 326-328, 330-334 Traces, stack, 38-1 40 Transfer, of data ownership, 33-34 Transition thread state, 56 Transitive causality, 483, 1 TreadAbo rt Exc eptions, 1 Tread ResetAbort API, 1 True dependence, 485 True waiting, 64-65 Try / finally block, 273-275 TryAndPe rform method, linked lists, 621 , 624 www.it-ebooks.info WWW.EBOOK777.COM 956 ==> www.ebook777.com free I ebo n d ex oks Try E n t e r method, CLR locks, 275-276 TryEnterCrit i c a lSect ion, 263-266 TryS ignalAndWa it, 653-654 TrySteal, work stealing queue, 637, 639-640 TrySubmi tThread poolC a l l b a c k API, Vista thread pool, 324-328 Two-phase locking protocols, 767 Two-step dance, 606-608 Type objects, 278-281 , 873-874 TypeLoadExc eption, 492 User-mode scheduling, 87 User-mode stacks, 82 allocated when creating new fibers, 436 overview of, 27-1 30 reservation and commit sizes of, 30-1 33 thread creation and, 53 v V (releasing), semaphores, 42 ! vadump command, 35-1 38 VADUMP.EXE, 35 U U LONG, 34 UMS (user-mode scheduler) advantages of fibers, 431 -432 defined, 430 UMS (user-mode scheduler), building, 453-473 context switches, 464-470 cooperative blocking, 461 -463 dispatching work, 461 fiber pool data structures, 455-459 overview of, 453-455 queueing work, 463-464 shutdown, 470-472 stack vs stackless blocking, 472-473 thread and fiber routines, 459-460 Unhandled exceptions overriding default behavior, 05-1 06 task parallel library, 893-895 terminating threads, 03-1 05 UnhandledExceptionsAre Fatal flag, TPL, 893 UNIX, 80 Un regi sterw ait ( E x ) , 362-363 Unrepeatable reads, 28 U n s afePa ck, CLR thread pool, 370 UnsafeQueueUserWorkltem, CLR thread pool, 364-366, 371 UnsafeRegi sterWai t F orSingleOb j e ct, CLR thread pool, 375 Unstarted thread state, 57 Unstructured concurrency, 896-897 Upgrading legacy RWLs, 302-303 ReaderWrit e r L o c k S l im, 294-297 User experience, and concurrency, User-mode APCs, 208, 209-2 User-mode scheduler See UMS (user-mode scheduler) VB Sync Loc k statement, 870 VC+ + creating fences i n , 4-51 process shutdown, 565-567 Virtual memory, 30-1 33 Virt u a lAlloc function, 38, 43 Virtua lQuery Win32 function, 49-1 51 volat ile variable creating fences, 3-51 interlocked operations, 494 lazy initialization in NET, 524-525 W Wait APIs, 800-802 Wait Chain Traversal (WCT), Windows Vista, 590, 594-597 Wait conditions, 878-879 Wait freedom, Wait graphs, 589-594 Wait method, Task class, 892-893 WAIT_ABANDONED value abandoned mutexes, 8-21 blocking and pumping messages, 99 process shutdown, 564, 568 waiting in Win32, 90-1 91 Waitable timers, 234-241 creating and opening, 235-236 overview of, 234-235 setting and waiting, 236-237 using F I L ETIMEs, 237-241 WAIT_A L L flags, 231 -232 WaitAl l , Wa itHandle class, 205-206 Wa itAn y , WaitHa ndle class, 205-206 WAIT_FAI L ED, 90-1 , 99 Wai t F o rMul t i p leObj ects ( Ex ) APls acquiring and releasing mutexes, alertable waits, 93-1 95 www.it-ebooks.info WWW.EBOOK777.COM m 957 free ebooks ==> www.ebook77I n7.co d ex building user-mode scheduler, 466-467 taking and releasing semaphores, 223-224 waiting in Win32, 90-1 93 wa i tForSingleObj ect ( E x ) APls abandoned mutexes and, 21 acquiring and releasing mutexes, 21 alertable waits, 93-1 95 taking and releasing semaphores, 223-224 waiting in Win32, 89-1 90 Wa itForThreadpoo lCa l l b a c k s , Vista, 328-330 Wa itForTh readpoolTimer, Vista, 334 Wai t F o rThreadpool TimerCa l l ba c k s, Vista, 334 Wai t F o rThreadpoolWa i t C a l l b a c k s, Vista, 339, 341-342, 347 Wa itHa n d l e class, 204-206, 374 WaitHa n d l e WaitAII, 202, 231 -232, 885 WaitHa n d l e WaitAny, 885 Wa itHandle WaitOne, 86 WaitHandle WaitTimeout, 206 Waiting Framework monitors, 309-3 avoiding deadlocks with, 576 c a l l ing AsyncWaitHand les' WaitOne method, 407-41 O causing deadlocks, 575 message waits, 95-1 98 in native code, 89-1 95 synchronization via kernel objects with, 84-1 86 using kernel objects, 88 Waiting, in control synchronization busy spin waiting, 63-64 continuation passing style vs., 65-66 monitors and condition variables, 68-70 real waiting in OS kernel, 64-65 NET using events, 66-68 Waiting state, threads, 56 WaitingReadCount, ReaderWriterLockSl im, 295 WaitingUpgradeCount, Readerwrite rLockSl im, 295 waitingWriteCount, ReaderWrit e r L o c k S l im, 295 WAIT_IO_COMP L ETION alertable waits, 93 asynchronous procedure calls and, 209 blocking and pumping messages, 99-201 WAIT_OBJ ECT_e, 90-1 , 99-202 waitOne method, APM, 407-41 0, WaitOne method, Wait H a n d l e class, 205-206 WaitOrTimerCa l l b a c k, CLR thread pool, 375 WaitSleepJoin thread state, 58-1 59, 207-208 WAIT_TIMEOUT, 90-1 , 99-201 Wake-all, stampedes, 605-606 Wake-one, stampedes, 605-606 Waking, condition variables and, 306-307, 309 WCF (Windows Communication Foundation), 72-73, 71 WCT (Wait Chain Traversal), Windows Vista, 590, 594-597 Weakening the lock, process shutdown, 563-564 WebCl i e nt, 427 WebReque st, APM, WF (Workflow Foundation), 71 9-720 while loops data parallelism and, 658-659, 661 iteration and, 672 Win32 bit operations in, 502-503 creating threads in, 90-96 critical sections See Critical sections, Win32 Dl lMa i n function in, 1 5-1 interlocked singly-linked lists, 538-540 process shutdown in, 562, 563-568 slim reader/ writer locks See SRWLs (slim reader/ writer locks) stack overflow disasters in, 41 terminating threads See Threads, termination methods thread local storage, 1 8-121 waiting in, 89-1 95 Win32 asynchronous I /O, 792 APC callback completion method, 806-808 asynchronous sockets I /O, 4-81 completing, 796 event handler completion method, 802-805 I / O completion ports completion method, 808-8 initiating, 792-796 overview of, 792 polling completion method, 798-800 synchronous completion method, 797-798 wait APls completion method, 800-802 Win32 legacy thread pool, 353-364 I / O completion ports, 359-360 overview of, 7-31 www.it-ebooks.info WWW.EBOOK777.COM 958 ==> www.ebook777.com free I ebo n d e oks Win32 legacy thread pool, tin ued performance of, 391 -397 registered waits, 360-363 thread management, 363-364 timers, 356-359 understanding, 353-354 work items, 354-356 WinObg command, 46 Window procedures, 831 Windows CLR threads vs., 85-87 GUls on, 831 kernel synchronization See Kernel synchronization processes, 80-81 spin waiting, 769-772 stack overflow disasters in, threads, 81 -85, 52-1 53 Windows Communication Foundation (WCF), 72-73, 71 Windows Forms, 837-840 identifying calls that need marshalling, 839 ISync h ron i z e I nvoke for marshalling cails, 838-839 overview of, 837-838 running message loop mid-stack, 839-840 Windows Performance Monitor (perfmon.exe), 56-1 57 Windows Presentation Foundation (WPF), 840-846 Windows Task Manager, 75 Windows Vista condition variables, 304-309 one-time initialization, 529-534 performance of, 391 -397 process shutdown in, 563-568 slim reader / writer lock, 288, 289-293 synchronous I / O cancellation, 823 Wait Chain Traversal, 590 Windows Vista thread pool, 323-353 callback completion tasks, 350-351 creating timers, 330-334 debugging, 353 environments, 342-347 I / O completion ports, 334-336 introduction to, 323-324 no thread ownership and, 352-353 overview of, 7-31 registered waits, 336-341 synchronization with callback completion, 341 -342 thread management, 347-350 work items, 324-330 Work callbacks, thread pools and, Work items CLR thread pool, 364-368 legacy Win32 thread pool, 354-356 thread pool performance and, 391 -397 Vista thread pool, 324-330 Work stealing queue, 636-640 Wo rkCa l l b a c k, 456-459, 461 Workflow Foundation (WF), 71 9-720 Workstations (concurrent), garbage collection, 766 WPF (Windows Presentation Foundation), 840-846 Write / read hazards, 28 Write / write hazards, 28 _WriteBa rrier, 529 Writ e F i le, 792 X X86 architecture, 509-5 1 , XADD instruction, 504 XCHG primitive, 493-499 www.it-ebooks.info WWW.EBOOK777.COM nr!t M i c rosoft Progra m m i ng/Concu rre n t Progra m m i n g free ebooks ==> www.ebook777.com 'When you begin using multi-threading throughout an application, the importance of clean architecture and design is critical Development Series This places an emphasis on understanding not only the pla tform 's capabilities but also emerging best practices Joe does a grea t job interspersing best practices alongside theory throughout his book " -Fro m the Fo reword by " S u p p o rted by the leaders a n d Craig M u nd i e Chief Research and Strategy Officer M i c rosoft Corporation Author J o e D u ffy h a s ri sen to t h e c h a l l e n g e of exp l a i n i n g how to write software that takes fu l l advantage of concu rre ncy and h a rdwa re para l l el i s m In Concurrent Programming on Windows, h e exp l a i n s h ow to d e s i g n i m p l e m e n t a n d m a i n t a i n l a rge-scale c o n c u rrent p ro g m s p ri m a ri l y using C# a n d C++ for W i n d ows p ri n c i pa l a u t h o ri t i e s of core M i c ro soft tec h n o l o g i e s t h i s series has a n a u t h o r pool that c o m b i n e s s o m e of t h e most i n s i g h tful a u t h o rs in t h e i n d u stry with t h e l ead softwa re a rch itects a n d developers at M i c rosoft a n d t h e developer c o m m u n ity at large - Do n Box D u ffy a i m s to g ive a p p l icati o n syste m a n d l i b ry d eve l o p e rs t h e Arc h itect M i c rosoft t o o l s a n d tec h n i q u es n e e d e d to write effi c i e n t safe c o d e f o r m u l t i c o re p rocessors T h i s is i m portant not o n l y fo r t h e k i n d s of p ro b l e m s where c o n c u rre n cy i s i n h e re nt a n d eas i ly exp l o i t a b l e-such a s s e rver " Th i s is a g reat res o u rce fo r p rofe S S i o n a l N ET d evelopers a p p l i c at i o n s c o m p u t e - i n t e n s ive i m a g e m a n i p u lation fi n a n c i a l a n a lys i s I t covers a l l bases fro m expert s i m u l ati o n s a n d AI a l g o rit h m s-but a l s o for p rob l e m s t h a t c a n b e p e rs pective to refe re n c e a n d speeded u p u s i n g p a l l e l i s m b u t req u i re m o re effort-s u c h as math h ow-to B o o k s i n t h i s s e r i e s a re l i b raries sort ro uti n e s re port g e n e rati o n XML m a n i p u lation and e s s e n t i a l read i n g fo r t h o s e who stream p roces s i n g a l g o rith m s want to j u d i c i o u s ly expand their kn owl e d g e base a n d expe rt i se " Concurrent Programming on Windows has four major sect io ns: The first introduces c o n cu rrency at a high level followed by a section that focuses on the fundamental platform fe atures , inner API d e tai l s Next the re is a section that describes worki ngs , and common pattern s best practices algorithms, and data structures that emerge while writing concurrent software The final section covers many of the common system-wide a rchitectural and process concerns of concurrent programming - Jo h n Montgomery Pri n c i pa l G ro u p Program Manager Developer Divi s i o n M i c rosoft " Th i s fore m o s t series on N ET c o n ta i n s vital i n formation for deve l o p e rs who need to get the most out of the N ET Fra m ework Our a u t h o rs a re s e l ected fro m t h e This is the only book you'll need in order to learn the best pract ices k e y i n n ovators who c reate t h e and common patterns for programmi ng with concurrency on tec h n o l ogy a n d a re t h e m o s t Windows and NET res pected p ract i t i o n e rs of i t " - B rad Abra m s Joe Duffy G ro u p Progra m M a n a g e r M i c rosoft is t h e deve l o p m e n t lead a rch itect a n d fo u n d e r of t h e Para l l e l Exte n s i o n s to t h e N ET Fra m ework team at M i c rosoft I n a d d i t i o n t o h a c ki n g code a n d m a n a g i n g a team o f deve l o p e rs h e works o n l o n g -term v i s i o n a n d i n c u bation effo rt s s u c h a s l a n g u a g e a n d type system s u p p o rt f o r c o n c u rre ncy safety H e p revi o u s l y worked o n t h e Co m m o n La n g u a g e R u n t i m e tea m J o e b l o g s reg u l a rly at www b l u ebytesoftwa re co m / b l o g i nform it.com/msdotnetseries Cover photograph by Jorg G reuel/ Gettyl mages I n c o Text p r i n t e d on recyc led paper ,"' , Addison-Wesley Pearson Education FREE Online Edition I S B N - : 978-0-321 -43482- ISBN- : 0-321 -43482-X with purchase of this book Details on last Page II IIII I I I I 78032 $49.99 www.it-ebooks.info WWW.EBOOK777.COM 4348 U.S I $54 99 CANADA ... exploit concurrency Understanding the concepts of concurrent programming and how to write concurrent code has therefore become a crucial part of writing successful software With Concurrent Programming. .. State Machines and Time Isolation 15 19 31 Immutability 34 Synchronization: Kinds and Techniques Data Synchronization 40 Coordination and Control Synchronization Where Are We? 38 60 73 xi www.it-ebooks.info... Reusable NET Libraries, Second Edition, 978-0-321-54561-9 Krzysztof Cwalina and Brad Abrams, Concurrent Programming on Windows, 978-0-321-43482-1 Joe Duffy, T he Common Language Infrastructure