Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


Share this Page URL
Help

5.5 Virtualizing Processors Using Threads > 5.5.2 Implementing YIELD - Pg. 260

260 CHAPTER 5 Enforcing Modularity with Virtualization 5.5.2 Implementing yield To keep the implementation of yield as simple as possible, let's temporarily restrict its implementation to a fixed number of threads, say, seven, and assume there are fewer than seven processors. (If there were seven or more processors and only seven threads, then processor virtualization would be unnecessary.) We further start by assuming that all seven threads run in the same address space, so we don't have to worry about saving and restoring a thread's pmar . Finally, we will assume that the threads are already running. (Section 5.5.3 will remove the last assumption, explaining how threads are created and how the thread manager starts.) With these assumptions we can implement yield as shown in Figure 5.24. The implementation of yield relies on four procedures: get _ thread _ id , enter _ processor _ layer , exit _ processor _ layer , and scheduler . Each procedure has only a few lines of code, but they are subtle; we investigate them in detail. As shown in the figure, the code for the procedures maintains two shared arrays: an array with one entry per processor, known as the processor_table , and an array with one entry per thread, known as the thread_table . The processor_table array records infor- mation for each processor. In this simple implementation, the information is just the identity of the thread that the processor is currently running. In later versions, we will