PDN-C14-PPT - Chapter 14 Multithreading Yingcai Xiao...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Chapter 14 Multithreading Yingcai Xiao
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Multithreading is a mechanism for performing two or more tasks concurrently. In the managed world of the common language runtime, the fundamental unit of execution is the thread. A managed application begins its life as a single thread but can spawn additional threads. Threads running concurrently share the CPU (or CPUs) by using scheduling algorithms provided by the system. To an observer, it appears as if all the threads are running at once. In reality, they simply share processor time. . Multithreading
Background image of page 2
Multithreading A single-threaded application uses just one processor at a time. A multithreaded application can have different threads running on different processors. Windows NT kernel (NT, 2000, XP, Vista) supports multiple processors using a strategy called symmetric multiprocessing (SMP). Versions that derive from Windows 95 (95, 98, Millennium) do not. .NET Framework’s threading API: to start, stop, manipulate, prioritize and synchronize threads.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Example using System; using System.Threading; class MyApp { static void Main () { for (int i=0; i<10; i++) { Thread thread = new Thread( new ThreadStart(ThreadFunc)); thread.Name = "My thread # " + i; thread.Start (); } }
Background image of page 4
Example static void ThreadFunc () { String name = Thread.CurrentThread.Name; for (int i=0; i<10; i++) { for( int j=0; j<100000000; j++); //work System.Console.WriteLine (name + " running at "+ DateTime.Now); } } }
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Starting a thread: 1. Create a thread object. 2. Setup a function for the thread to run. 3. Start the thread. Thread thread = new Thread (new ThreadStart (ThreadFunc)); thread.Start (); 4. Start simply makes the thread eligible to be allotted CPU time. The system decides when the thread begins running and how often it’s accorded processor time. 5. When a thread function returns, the corresponding thread ends.
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/21/2011 for the course CS 573 taught by Professor Dr.xiao during the Spring '10 term at The University of Akron.

Page1 / 16

PDN-C14-PPT - Chapter 14 Multithreading Yingcai Xiao...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online