This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
api:thread:zh [2023/10/20 13:15] hfsr [Thread Exception Example] |
api:thread:zh [2023/10/20 13:20] hfsr [Thread Yield/Pull Without Blocking Example] |
||
---|---|---|---|
Line 323: | Line 323: | ||
``` | ``` | ||
- | ===== Thread Interrupt Handler Example ===== | + | ===== 线程中断处理函数样例 ===== |
- | This example demonstrates how you would register a function that handles soft interrupts (^c) to close file handles, release resources, etc, and then exit the whole program. | + | 此样例演示了你该如何注册处理软中断(^c)的函数,用于关闭文件句柄、释放资源等等,然后退出整个程序。 |
```lua | ```lua | ||
Line 345: | Line 345: | ||
thread.waitForAny({cleanup_thread, main_thread}) | thread.waitForAny({cleanup_thread, main_thread}) | ||
- | os.exit(0) -- closes all remaining threads | + | os.exit(0) -- 关闭所有剩余线程 |
``` | ``` | ||
- | Assuming the user presses ^c to send an interrupt | + | 假设用户按下了^c发送了一次软中断 |
- | Output | + | |
+ | 输出: | ||
``` | ``` | ||
main program | main program | ||
Line 356: | Line 357: | ||
``` | ``` | ||
- | ===== Thread Yield/Pull Without Blocking Example ===== | + | ===== 非阻塞式线程Yield/Pull操作样例 ===== |
- | This example demonstrates that now OpenOS supports non blocking threads. | + | 此样例演示了现在OpenOS可支持非阻塞式线程。 |
```lua | ```lua | ||
Line 374: | Line 375: | ||
``` | ``` | ||
- | Output | + | 输出: |
``` | ``` | ||
custom_event_a | custom_event_a |