.NET Fireside Chats - Joe Duffy on 'Concurrent Programming on Windows'
Join the DZone community and get the full member experience.
Join For Freedzone recently had a chance to sit down with joe duffy, author of ' concurrent programming on windows '. in this interview, joe discusses the origins and benefits of concurrent development in a windows environment, and the future of parallel programming with the .net framework.
dzone has also made available chapter 2 from joe's book, which can be downloaded here .
dzone - tell us a little about what you do at microsoft?
joe duffy -
i have two primary roles at microsoft. first, i manage the team of developers who are creating the parallel extensions technology, a collection of new libraries which will appear in .net 4.0 (aka visual studio 2010). that includes parallel linq (plinq) and the task parallel library (tpl). and second, i am the architect for those and related technologies, like exploring concurrency safe type system extensions to the c# language. i write plenty of code too.
dzone - what motivated you to write this book?
joe -
my prior job was the concurrency program manager for the clr team. in that role, i was responsible for the system.threading namespace and corresponding runtime support, and also managed a few projects related to what eventually became parallel extensions (and some that is still in the works, like software transactional memory). there simply was no good book on concurrency for windows or .net available at the time. (and that didn’t change in the 2 ½ years i worked on this book.) so i decided that, in addition to learning the topic inside and out, i should write it down for others to learn from too.
dzone - what is concurrent (or parallel) programming? give us the nickel tour.
joe -
concurrency is everywhere, and (put as simply as possible) is the act of running multiple things at once. on windows, those things are threads. parallel programming is the act of using concurrency to utilize more hardware at once for a performance gain. concurrency has existed in operating systems and server-side programs, and parallelism has been common to specialized domains like high-performance- and scientific-computing, for decades. only recently has parallelism become forefront in client-side applications. indeed it’s now a crucial skill for all developers to have in their arsenal.
dzone - what are some of the hardest problems that developers are trying to solve when it comes to concurrent programming with .net?
joe -
the three hardest problems are, in no particular order: (1) finding opportunities for parallelism, (2) arranging for parallelism to occur, and (3) dealing with the consequences of concurrency and shared state. the third category is perhaps the best known, and conjures up words like race condition, deadlock, and priority inversion. the lack of good books and abstractions in the platform has made these problems even more difficult for developers to deal with.
dzone - what kinds of features are currently available in the .net framework 3.x to support concurrent programming?
joe -
windows has built up a solid foundation for concurrent programming over the 15-or-so years since windows nt 3.5. each release has come with new improvements, ranging from new apis—like the wait chain traversal and user-mode reader/writer locks in windows vista—to subtle and often-unnoticed improvements—like the use of keyed events for low resource conditions and the elimination of the single global scheduler lock in the kernel. .net builds atop the os support, and thus benefits also. but it brings along its own improvements—like its own new reader/writer lock and an overhaul of the .net threadpool from release 3.0 to 3.5. the improvements coming in .net 4.0 are perhaps the most substantial to date.
dzone - what are some of the biggest enhancements coming in .net 4.0 in this space?
joe -
tpl provides a new scheduler that uses work-stealing to eliminate scaling bottlenecks and make it far easier to benefit from fine-grained parallelism. it also offers a rich set of abstractions—like tasks with cancellation and parent/child relationships, parallel for loops, easy divide-and-conquer support, and more. plinq runs any linq query in parallel, taking advantage of linq’s mostly-functional nature. a set of other types, the coordination data structures (cds), accommodates other synchronization needs, including a blocking/bounded collection type, a unified cancellation framework, and a rich set of concurrent collections. there are too many specifics to list here. i recommend folks check out http://msdn.microsoft.com/concurrency/ to read some articles and download our preview releases. my book also has an appendix describing the preview bits.
dzone - how is microsoft leveraging parallel programming internally?
joe -
multicore is still in its infancy. we stand at the beginning of the long adoption curve, and my team has had to deal with the chicken-and-the-egg problem. that said, i just got an email last week from an internal team that used parallel extensions to speed up the install time of their product by 4x on 4-core machines. i get emails like this describing one-off successes all the time. many product teams are still experimenting with the best way to incorporate parallelism and how to use it to improve their software’s capabilities. other teams—particularly in microsoft research—are using parallelism to perform increasingly sophisticated analyses on increasingly large sets of data, and tackling some pretty epic problems. some groups have even dedicated entire teams to exploring how parallelism can help to improve applications with immersive capabilities like speech and vision. i personally believe that we'll soon be leaving the “toying around” phase of multicore and entering the phase where parallelism is used for true competitive advantages in the next 1-3 years.
dzone - are there any best practices people can follow?
joe -
the book lists many, and in fact has a consolidated list in one of the appendices. if i could boil them down into a brief sound bite, however, it would be: program functionally where possible; avoid sharing (aka isolate state) where functional isn’t possible (or performant); and tread with great care when you need to mutate shared state (as not only is it dangerous, but it will negatively impact the performance benefits parallelism can bring). languages like f# can help folks attain this vision, but there is no silver bullet. awareness and thoughtfulness can go a long way.
dzone - are there any interesting case studies that you can discuss? have you implemented a recent project using concurrent programming?
joe -
i talk to customers all the time who are trying to retrofit parallelism into their existing applications. most successes i’ve heard from have been around so-called embarrassingly parallel problems. these are those where either computations are large, data sets are large, or some combination of the two, and where the processing that goes on is easily divisible. graphics applications, game engines, cad systems, financial modeling, advanced mathematical problems (like constraint satisfaction), business intelligence and reporting, and certain ai search algorithms are just a few examples.
dzone - who should buy your book?
joe -
the book is meant for any .net or c++ developer whose software needs to run on windows. i don’t think many more caveats are needed. i fully believe that all programmers will need to know how to deal with threading in order to remain marketable 5 years out. my book covers both client- and server-side concurrency, and isn't only meant for the new kinds of parallel programming that apply to the multicore era. it really can be used for the kind of software that's already being written today, in addition to being applicable for the software of tomorrow. most of all, the book is meant for geeks who (like me) aren’t satisfied until they understand the ins and outs of how everything most people take for granted actually works under the covers. if you like books like windows internals, then this book is for you.
dzone - do you have any future books in the works?
joe -
you bet. my next book is called “notation and thought: behind computer science’s most influential programming languages.” i’ve always had a fascination with programming languages, the history behind them, and the people who created them. this book is an exploration of that, telling the story behind 20-something of the most influential languages. i believe we’re standing on the edge of a programming language renaissance. too much of the computing landscape is undergoing major changes for the languages we use to remain constant. you can already see trends towards dynamic and function languages bucking the standard statically-typed, c language trend that dominated the 80’s and 90’s, and domain specific languages are on the rise. and interestingly, the multicore era demands new language constructs to enable safe and deterministic programming in the face of large-scale concurrency. this is proving to be an incredibly fun book to write.
Opinions expressed by DZone contributors are their own.
Comments