24

Introduction to Multi-threading in C#

24.1 INTRODUCTION AND OBJECTIVES

In this part of the book we introduce a number of design and software tools to help developers take advantage of the computing power of multi-core processors and multi-processor computers. These computers support parallel programming models. The main reason for writing parallel code is to improve the performance (called the speedup) of software programs. Another advantage is that multi-threaded code can also promote the responsiveness of applications in general.

We introduce a new programming model in this chapter. This is called the multi-threading model and it allows us to write software systems whose tasks can be carried out in parallel. This chapter is an introduction to multi-threaded programming techniques. We introduce the most important concepts that we need to understand in order to write multi-threaded applications in C#. A thread is a single sequential flow of control within a program. However, a thread itself is not a program. It cannot run on its own, but instead it runs within a program. A thread also has its own private data and it may be able to access shared data.

When would we create multi-threaded applications? The general answer is performance. Some common scenarios are:

  • Parallel programming: much of the code in computational finance implements compute intensive algorithms whose performance (called the speedup) we wish to improve by using a divide-and-conquer strategy to assign parts ...

Get C# for Financial Markets now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.