Thread - anantakul · needs to seamlessly resume execution, including the thread's set of CPU...
Transcript of Thread - anantakul · needs to seamlessly resume execution, including the thread's set of CPU...
![Page 2: Thread - anantakul · 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](https://reader035.fdocuments.in/reader035/viewer/2022063013/5fccb7b23398194e416995ae/html5/thumbnails/2.jpg)
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
![Page 3: Thread - anantakul · 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](https://reader035.fdocuments.in/reader035/viewer/2022063013/5fccb7b23398194e416995ae/html5/thumbnails/3.jpg)
Multitasking & Multithreading
Windows
Word Games Browser
Process1 Process2 Process3
Windows
Word Game Browser
Process1 Process2 Process3
thread1 thread2 thread3
![Page 4: Thread - anantakul · 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](https://reader035.fdocuments.in/reader035/viewer/2022063013/5fccb7b23398194e416995ae/html5/thumbnails/4.jpg)
การท างานหลายงานพร้อมกนั
![Page 5: Thread - anantakul · 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](https://reader035.fdocuments.in/reader035/viewer/2022063013/5fccb7b23398194e416995ae/html5/thumbnails/5.jpg)
Thread in Multithreading
![Page 6: Thread - anantakul · 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](https://reader035.fdocuments.in/reader035/viewer/2022063013/5fccb7b23398194e416995ae/html5/thumbnails/6.jpg)
วฏัจกัรของเธรด (Thread Life Cycle)
![Page 7: Thread - anantakul · 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](https://reader035.fdocuments.in/reader035/viewer/2022063013/5fccb7b23398194e416995ae/html5/thumbnails/7.jpg)
Start() and Sleep()
• Start() สัง่ให้ thread เร่ิมท ำงำนและเข้ำสูส่ถำนะ ready
• Sleep() ให้ thread พกัเข้ำสูส่ถำนะ Sleeping
![Page 8: Thread - anantakul · 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](https://reader035.fdocuments.in/reader035/viewer/2022063013/5fccb7b23398194e416995ae/html5/thumbnails/8.jpg)
Join() and Stop()
• Join() ก ำหนดให้ thread ลกูท ำงำนให้เสร็จก่อน
• Stop() ก ำหนดให้ thread หยดุท ำงำน
![Page 9: Thread - anantakul · 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](https://reader035.fdocuments.in/reader035/viewer/2022063013/5fccb7b23398194e416995ae/html5/thumbnails/9.jpg)
Example 1: Creating, starting, and interacting between threads
9
เร่ิมท ำงำน
เช่ือมต่อกำรท ำงำน
หยดุพกั
![Page 10: Thread - anantakul · 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](https://reader035.fdocuments.in/reader035/viewer/2022063013/5fccb7b23398194e416995ae/html5/thumbnails/10.jpg)
Example 2: Creating join between threads
10
![Page 11: Thread - anantakul · 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](https://reader035.fdocuments.in/reader035/viewer/2022063013/5fccb7b23398194e416995ae/html5/thumbnails/11.jpg)
Example 3: Creating threads in Application Form
11
![Page 12: Thread - anantakul · 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](https://reader035.fdocuments.in/reader035/viewer/2022063013/5fccb7b23398194e416995ae/html5/thumbnails/12.jpg)
suspend() and resume()
• suspend() สัง่ให้ thread หยดุท ำงำนและเข้ำสูส่ถำนะ blocked
• resume() ให้ thread เข้ำสูส่ถำนะ ready