Design of Multithreaded Software
Press Operating Committee
Chair
Linda Shafer
former Director, Software Quality Institute
The University of Texas at Austin
Editor-in-Chief
Alan Clements
Professor
University of Teesside
Board Members
Mark J. Christensen, Independent Consultant
James W. Cortada, IBM Institute for Business Value
Richard E. (Dick) Fairley, Founder and Principal Associate ,
Software Engineering Management Associates (SEMA)
Phillip Laplante, Professor of Software Engineering, Penn State University
Evan Butterfi eld, Director of Products and Services
Kate Guillemette, Product Development Editor, CS Press
IEEE Computer Society Publications
The world-renowned IEEE Computer Society publishes, promotes, and distributes a wide variety of authoritative computer science and engineering texts. These books are available from most retail outlets. Visit the CS Store at http://computer.org/store for a list of products.
IEEE Computer Society / Wiley Partnership
The IEEE Computer Society and Wiley partnership allows the CS Press authored book program to produce a number of exciting new titles in areas of computer science, computing and networking with a special focus on software engineering. IEEE Computer Society members continue to receive a 15% discount on these titles when purchased through Wiley or at wiley.com/ieeecs
To submit questions about the program or send proposals please e-mail kguillemette@computer.org or write to Books, IEEE Computer Society, 10662 Los Vaqueros Circle, Los Alamitos, CA 90720-1314. Telephone +1-714-816-2169.
Additional information regarding the Computer Society authored book program can also be accessed from our web site at http://computer.org/cspress .
Java is a registered trademark of Sun Microsystems, Inc.
LEGO is a registered trademark of the LEGO Group.
POSIX is a registered trademark of IEEE.
UML is a registered trademark of Object Management Group, Inc.
UNIX is a registered trademark of The Open Group.
Copyright 2011 by the IEEE Computer Society
Published by John Wiley & Sons, Inc., Hoboken, New Jersey. All rights reserved
Published simultaneously in Canada
No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning, or otherwise, except as permitted under Section 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, Inc., 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 750-4470, or on the web at www.copyright.com . Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at www.wiley.com/go/permission .
Limit of Liability/Disclaimer of Warranty: While the publisher and author have used their best efforts in preparing this book, they make no representations or warranties with respect to the accuracy or completeness of the contents of this book and specifically disclaim any implied warranties of merchantability or fitness for a particular purpose. No warranty may be created or extended by sales representatives or written sales materials. The advice and strategies contained herein may not be suitable for your situation. You should consult with a professional where appropriate. Neither the publisher nor author shall be liable for any loss of profit or any other commercial damages, including but not limited to special, incidental, consequential, or other damages.
For general information on our other products and services or for technical support, please contact our Customer Care Department within the United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic formats. For more information about Wiley products, visit our web site at www.wiley.com .
Library of Congress Cataloging-in-Publication Data is available.
ISBN 978-0470-87659-6
oBook ISBN: 978-0470-90491-6
ePDF ISBN: 978-0470-90490-9
Foreword
A s computer-based systems become ever more ambitious and ever more complex, it is vital to keep a firm grasp of the fundamental ideas of their conception and design. This book focuses on one of the most fundamental ideas of all. The world we inhabit, and our experiences in it, have an inescapable time dimension. To deal properly with the world and to satisfy the functional requirements of the systems we build, we must master the intrinsic complexities of this time dimension. Many sequential processes progress in parallel in the world, interacting wherever events in two processes involve the same entity. The computer software must mirror, respect, and exploit this sequentiality and concurrency, and also add its own interacting processes to implement the additional behaviour and control necessary to satisfy the requirements.
Bo Sandn has written a splendid book that should be read by every developer of systems that interact with the real world. The multithreading theme that gives the book its title treats the identification and design of individual threadsthat is, of concurrent processesand the synchronisation and control of their interactions at common entities. The book succeeds excellently in this difficult area, expounding patterns of thread interaction that clarify both the problems they address and the solutions they offer.
The developer of a system of this kind must give explicit consideration both to the real world and to the world inside the computer and must recognise clearly that these are distinct, though interrelated, worlds. In some development approaches these distinct worlds are subtly confused, especially where the software itself embodies a modelthat is, a surrogate or simulationof the real world. Some writers on object-oriented development take too little thought for the distinction between a software object and the real-world entity it models. Their readers are then disinclined to pay enough attention to the real world, and the resulting systems are not quite fit for purpose. In this book, Sandn has taken care to make a clear and explicit distinction between event threads in the real world and the related control threads in the software: He gives both the real world and the software world the attention that is their due. This is a book for designers and programmers who want to align their software faithfully to the real-world requirements that they are striving to satisfy.
The central justification of a focus on threads and concurrency is the fundamental role of time in the world and in the computer, but it has another virtue too. The thread structurecapturing the role of each thread and its interactions with other threadsforms an excellent basis for the software architecture. An object structure alone cannot inform an architecture. Sandn points out that a thread structure can embody the key idea of a software architecture, clearly exposing the concept and underlying principle of the system design. This notion chimes well with the notion of the operational principle of a machine expounded by the physical chemist and philosopher Michael Polanyi. The operational principle of a machine specifies how its characteristic partsits organsfulfill their special function in combining to an overall operation which achieves the purpose of the machine. It describes how each organ acts on another organ within this context. An object structure alone cannot reveal the operational principle of a system, but the thread structure, where threads are associated either with objects or with execution of system functions, can reveal it clearly and memorably. The book has several problem examples that illustrate architectural choice by presenting alternative thread structures embodying alternative operational principles.