O'Reilly logo

.NET Common Language Runtime Unleashed by Kevin Burton

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

Synchronization

Starting and manipulating a Thread is the easy part, made easier with the classes and facilities that the CLR provides. The hard part is synchronizing access to and manipulation of shared data.

When you are accessing or manipulating shared data, critical sections of code often have to happen atomically or not at all. In Listing 11.12, the critical section is the loop in the Thread entry point. You want all of the data generated in the loop to occur at the same time, uninterrupted. This could just as easily have been links in a linked list or shared variables being swapped. It is easier to show the interruption with a simple loop. To make sure that the OS will preempt the Thread, a Fibonacci number will be computed to simulate ...

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