O'Reilly logo

Shared Source CLI Essentials by Ted Neward, Geoff Shilling, David Stutz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Threading and Concurrency

Reading to this point in this chapter, one might think that threads serve as little more than a place to do frame bookkeeping. While this aspect of threads is certainly important, the primary role of threads has always been to organize programming tasks into understandable units of concurrency and synchronization. We will now turn our attention to this more familiar facet of threading, and examine how programmers can use managed threads to build concurrent applications.

Threads are the primary abstraction for execution and concurrency in the CLI. Because the CLI includes support for concurrent execution, it must also allow independently executing parts of a program to communicate and to synchronize their state, as well as provide programmers with the ability to impact the scheduling of concurrent activity.

The execution engine provides mechanisms for all of these:

  • Programmers can communicate between component references that have been marshaled between threads using method calls.

  • Programmers can synchronize access to instance and static methods, instance fields, and arbitrary regions of their components, either automatically or manually.

  • Programmers can control thread scheduling by manipulating instances of the Thread component or by using the CLI threadpool, which is an efficient runtime service that simplifies worker thread creation and scheduling.

We will visit each of these mechanisms in turn; but first, we will examine how managed threads are implemented. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required