thread - anantakul · needs to seamlessly resume execution, including the thread's set of cpu...
TRANSCRIPT
Threads and Threading
Operating systems use processes to separate the different applications that they are executing. Threads are the basic unit to which an operating system allocates processor time, and more than one thread can be executing code inside that process. Each thread maintains exception handlers, a scheduling priority, and a set of structures the system uses to save the thread context until it is scheduled. The thread context includes all the information the thread needs to seamlessly resume execution, including the thread's set of CPU registers and stack, in the address space of the thread's host process.
2
Multitasking & Multithreading
Windows
Word Games Browser
Process1 Process2 Process3
Windows
Word Game Browser
Process1 Process2 Process3
thread1 thread2 thread3
การท างานหลายงานพร้อมกนั
Thread in Multithreading
วฏัจกัรของเธรด (Thread Life Cycle)
Start() and Sleep()
• Start() สัง่ให้ thread เร่ิมท ำงำนและเข้ำสูส่ถำนะ ready
• Sleep() ให้ thread พกัเข้ำสูส่ถำนะ Sleeping
Join() and Stop()
• Join() ก ำหนดให้ thread ลกูท ำงำนให้เสร็จก่อน
• Stop() ก ำหนดให้ thread หยดุท ำงำน
Example 1: Creating, starting, and interacting between threads
9
เร่ิมท ำงำน
เช่ือมต่อกำรท ำงำน
หยดุพกั
Example 2: Creating join between threads
10
Example 3: Creating threads in Application Form
11
suspend() and resume()
• suspend() สัง่ให้ thread หยดุท ำงำนและเข้ำสูส่ถำนะ blocked
• resume() ให้ thread เข้ำสูส่ถำนะ ready