Dr. Dobb's Journal - November 2008 - (Page 43) Locking Multiple Mutexes Without Deadlock One of the biggest issues with writing multithreaded code is the possibility of deadlock. One case where it is particularly problematic is where you must acquire locks on more than one mutex in order to perform an operation. Unless this is done carefully, different threads could attempt to acquire the locks in different orders, and thus each end up holding some locks whilst waiting for the others: deadlock! If you can structure your code so that the locks can be acquired together, the 1.36.0 release of Boost provides a solution to that in the form of the boost::lock() and boost::try_lock() functions. These function templates let you specify up to five individual Lockable objects to lock, or an iterator range. They will then attempt to lock all the objects. lock() will block until it can acquire all the locks, but will not hold any locks while it is blocking. The algorithm used ensures that lock() will not deadlock with any other thread that attempts to acquire the same set of locks, in whatever order. try_lock() will either acquire all or none of the set; the return value indicates the success or failure of the call, and which lock couldn’t be acquired in the case of failure. One case where they can be used is for the comparison of two objects that can also be modified by other threads, and so the member data must be protected by a mutex. If two threads try and compare the same two objects, they need to ensure their mutexes are locked in the same order to avoid deadlock. This is where boost::lock comes in: It enables both to be locked without the user having to worry about the order. In the following example, boost::lock is used to lock the mutexes, then ownership of those locks is adopted by some scoped_lock objects to ensure the locks are correctly released when the function exits: struct my_class { mutable boost::mutex m; int x,y; }; bool operator<(my_class const& lhs,my_class const& rhs) { boost::lock(lhs.m,rhs.m); boost::mutex::scoped_lock lk1(lhs.m,boost::adopt_lock); boost::mutex::scoped_lock lk2(rhs.m,boost::adopt_lock); return (lhs.x<rhs.x) || ((lhs.x==rhs.x) && (lhs.y<rhs.y)); } Living in a Digital Imaging World WHERE IT ALL BEGAN Founded in 1991 and headquartered in Tampa, Florida, Pegasus Imaging Corporation delivers digital imaging software development components, image compression and image editing technologies. The company exceeds speed and quality requirements for document imaging, forms processing, medical imaging, color/photo imaging, video applications and more. Technology is delivered as Microsoft Living in a Digital Imaging World WHERE IT ALL BEGAN Founded in 1991 and headquartered in Tampa, Florida, Pegasus Imaging Corporation delivers digital imaging software development components, image compression and image editing technologies. The company exceeds speed and quality requirements for document imaging, forms processing, medical imaging, color/photo imaging, video applications and more. Technology is delivered as Microsoft SCANNED TIFF .NET controls, COM controls, DLLs and applications. Multiple platforms are supported, including Windows, LINUX, Solaris, IBM AIX and Mac OS X. This image is here to show how incredible the compression is for the Pegasus imaging products. It handles images as well as text. .NET controls, COM controls, DLLs and applications. Multiple platforms are supported, including Windows, LINUX, Solaris, IBM AIX and Mac OS X. This image is here to show how incredible the compression is for the Pegasus imaging products. It handles images as well as text. AN EYE ON GROWTH Pegasus Imaging Corporation was founded in 1991 as a reseller of fractal image compression and decompression toolkits and digital image compression applications. The company entered the imaging marketplace at a very early stage with a far-reaching vision. To satisfy customer demand for well-supported commercial image compression technologies, the company focused on optimizing standards-based compression technology for speed and quality. Pegasus was rapidly shifting from being a provider of end user utilities to marketing business-to-business solutions. A testament to the company’s technology leadership, Pegasus Imaging is the only surviving commercial supplier of JPEG compression technology in the world. Well known photo imaging customers of Pegasus JPEG today include Kodak, Canon, Nikon, Fujifilm, Konica Minolta, and many others. The company’s strategy in the mid-1990s was to clearly differentiate Pegasus from its competition through investment in digital imaging research and development. The company’s senior scientists joined the team at this time. They are recognized throughout the industry, and provide Pegasus with a solid competitive edge. Pegasus Imaging is distinguished by its ability to deliver multiple interfaces to advanced technologies based on an extensive collection of intellectual capital, scientific research, and product innovations. Today, the company holds a portfolio of 11 patents granted, 12 patents pending, and a AN EYE ON GROWTH Pegasus Imaging Corporation was founded in 1991 as a reseller of fractal image compression and decompression toolkits and digital image compression applications. The company entered the imaging marketplace at a very early stage with a far-reaching vision. To satisfy customer demand for well-supported commercial image compression technologies, the company focused on optimizing standards-based compression technology for speed and quality. Pegasus was rapidly shifting from being a provider of end user utilities to marketing business-to-business solutions. A testament to the company’s technology leadership, Pegasus Imaging is the only surviving commercial supplier of JPEG compression technology in the world. Well known photo imaging customers of Pegasus JPEG today include Kodak, Canon, Nikon, Fujifilm, Konica Minolta, and many others. The company’s strategy in the mid-1990s was to clearly differentiate Pegasus from its competition through investment in digital imaging research and development. The company’s senior scientists joined the team at this time. They are recognized throughout the industry, and provide Pegasus with a solid competitive edge. Pegasus Imaging is distinguished by its ability to deliver multiple interfaces to advanced technologies based on an extensive collection of intellectual capital, scientific research, and product innovations. Today, the company holds a portfolio of 11 patents granted, 12 patents pending, and a SEARCHABLE PDF ONE OF THESE IMAGES IS 66% * THAN THE OTHER. With Pegasus Imaging SDKs, you can turn a scanned TIFF into a searchable image-over-text PDF and make the file a fraction of its original size. Save server space and search documents that were originally not searchable. We’ll show you how we do it, and give you the sample code in C#. Challenge our support team with your next imaging question. If they can’t answer it, our scientists surely will. CHECK OUT OUR NEW WHITE PAPER & FREE SAMPLE CODE. PEGASUSIMAGING.COM/TIFF-TO-PDF SMALLER PEGASUSIMAGING.COM (800) 875-7009 Pegasus is a registered trademark of Pegasus Imaging Corporation in the United States. *Results vary depending on image content. November 2008 l www.ddj.com l Dr. Dobb’s Journal 43 http://www.PEGASUSIMAGING.COM/TIFF-TO-PDF http://www.PEGASUSIMAGING.COM http://www.PEGASUSIMAGING.COM http://www.ddj.com
Table of Contents Feed for the Digital Edition of Dr. Dobb's Journal - November 2008 Dr. Dobb's Journal - November 2008 Contents Friday Night Fish Fry Alia Vox Developer Diaries Developer's Notebook Saving Open Source Conversations iPhone Building Your Own Web Server Green Telnet What's New In Boost Threads? Testing Service Oriented Architectures Test Case Generation, UML, and Eclipse Unit Testing Web Services C3 Programming The Agile Edge Swaine's Flames Effective Concurrency Dr. Dobb's Journal - November 2008 Dr. Dobb's Journal - November 2008 - (Page BB1) Dr. Dobb's Journal - November 2008 - (Page BB2) Dr. Dobb's Journal - November 2008 - Dr. Dobb's Journal - November 2008 (Page Cover1) Dr. Dobb's Journal - November 2008 - Dr. Dobb's Journal - November 2008 (Page Cover2) Dr. Dobb's Journal - November 2008 - Dr. Dobb's Journal - November 2008 (Page 1) Dr. Dobb's Journal - November 2008 - Dr. Dobb's Journal - November 2008 (Page 2) Dr. Dobb's Journal - November 2008 - Dr. Dobb's Journal - November 2008 (Page 3) Dr. Dobb's Journal - November 2008 - Contents (Page 4) Dr. Dobb's Journal - November 2008 - Contents (Page 5) Dr. Dobb's Journal - November 2008 - Friday Night Fish Fry (Page 6) Dr. Dobb's Journal - November 2008 - Friday Night Fish Fry (Page 7) Dr. Dobb's Journal - November 2008 - Friday Night Fish Fry (Page 8) Dr. Dobb's Journal - November 2008 - Friday Night Fish Fry (Page 9) Dr. Dobb's Journal - November 2008 - Alia Vox (Page 10) Dr. Dobb's Journal - November 2008 - Alia Vox (Page 11) Dr. Dobb's Journal - November 2008 - Developer Diaries (Page 12) Dr. Dobb's Journal - November 2008 - Developer Diaries (Page 13) Dr. Dobb's Journal - November 2008 - Developer's Notebook (Page 14) Dr. Dobb's Journal - November 2008 - Developer's Notebook (Page 15) Dr. Dobb's Journal - November 2008 - Saving Open Source (Page 16) Dr. Dobb's Journal - November 2008 - Saving Open Source (Page 17) Dr. Dobb's Journal - November 2008 - Saving Open Source (Page 18) Dr. Dobb's Journal - November 2008 - Saving Open Source (Page 19) Dr. Dobb's Journal - November 2008 - Conversations (Page 20) Dr. Dobb's Journal - November 2008 - Conversations (Page 21) Dr. Dobb's Journal - November 2008 - iPhone (Page 22) Dr. Dobb's Journal - November 2008 - iPhone (Page 23) Dr. Dobb's Journal - November 2008 - iPhone (Page 24) Dr. Dobb's Journal - November 2008 - iPhone (Page 25) Dr. Dobb's Journal - November 2008 - iPhone (Page 26) Dr. Dobb's Journal - November 2008 - iPhone (Page 27) Dr. Dobb's Journal - November 2008 - Building Your Own Web Server (Page 28) Dr. Dobb's Journal - November 2008 - Building Your Own Web Server (Page 29) Dr. Dobb's Journal - November 2008 - Building Your Own Web Server (Page 30) Dr. Dobb's Journal - November 2008 - Building Your Own Web Server (Page 31) Dr. Dobb's Journal - November 2008 - Building Your Own Web Server (Page 32) Dr. Dobb's Journal - November 2008 - Green Telnet (Page 33) Dr. Dobb's Journal - November 2008 - Green Telnet (Page 34) Dr. Dobb's Journal - November 2008 - Green Telnet (Page 35) Dr. Dobb's Journal - November 2008 - Green Telnet (Page 36) Dr. Dobb's Journal - November 2008 - Green Telnet (Page 37) Dr. Dobb's Journal - November 2008 - Green Telnet (Page 38) Dr. Dobb's Journal - November 2008 - Green Telnet (Page 39) Dr. Dobb's Journal - November 2008 - What's New In Boost Threads? (Page 40) Dr. Dobb's Journal - November 2008 - What's New In Boost Threads? (Page 41) Dr. Dobb's Journal - November 2008 - What's New In Boost Threads? (Page 42) Dr. Dobb's Journal - November 2008 - What's New In Boost Threads? (Page 43) Dr. Dobb's Journal - November 2008 - What's New In Boost Threads? (Page 44) Dr. Dobb's Journal - November 2008 - What's New In Boost Threads? (Page 45) Dr. Dobb's Journal - November 2008 - Testing Service Oriented Architectures (Page 46) Dr. Dobb's Journal - November 2008 - Testing Service Oriented Architectures (Page 47) Dr. Dobb's Journal - November 2008 - Testing Service Oriented Architectures (Page 48) Dr. Dobb's Journal - November 2008 - Test Case Generation, UML, and Eclipse (Page 49) Dr. Dobb's Journal - November 2008 - Test Case Generation, UML, and Eclipse (Page 50) Dr. Dobb's Journal - November 2008 - Test Case Generation, UML, and Eclipse (Page 51) Dr. Dobb's Journal - November 2008 - Test Case Generation, UML, and Eclipse (Page 52) Dr. Dobb's Journal - November 2008 - Unit Testing Web Services (Page 53) Dr. Dobb's Journal - November 2008 - Unit Testing Web Services (Page 54) Dr. Dobb's Journal - November 2008 - Unit Testing Web Services (Page 55) Dr. Dobb's Journal - November 2008 - Unit Testing Web Services (Page 56) Dr. Dobb's Journal - November 2008 - Unit Testing Web Services (Page 57) Dr. Dobb's Journal - November 2008 - Unit Testing Web Services (Page 58) Dr. Dobb's Journal - November 2008 - C3 Programming (Page 59) Dr. Dobb's Journal - November 2008 - C3 Programming (Page 60) Dr. Dobb's Journal - November 2008 - C3 Programming (Page 61) Dr. Dobb's Journal - November 2008 - C3 Programming (Page 62) Dr. Dobb's Journal - November 2008 - C3 Programming (Page 63) Dr. Dobb's Journal - November 2008 - The Agile Edge (Page 64) Dr. Dobb's Journal - November 2008 - The Agile Edge (Page 65) Dr. Dobb's Journal - November 2008 - The Agile Edge (Page 66) Dr. Dobb's Journal - November 2008 - The Agile Edge (Page 67) Dr. Dobb's Journal - November 2008 - Effective Concurrency (Page 68) Dr. Dobb's Journal - November 2008 - Effective Concurrency (Page 69) Dr. Dobb's Journal - November 2008 - Effective Concurrency (Page 70) Dr. Dobb's Journal - November 2008 - Effective Concurrency (Page 71) Dr. Dobb's Journal - November 2008 - Swaine's Flames (Page 72) Dr. Dobb's Journal - November 2008 - Swaine's Flames (Page Cover3) Dr. Dobb's Journal - November 2008 - Swaine's Flames (Page Cover4)
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.