Skip to content

Commit cded444

Browse files
committed
add rethink_of_try_catch_and_result
1 parent 1b6d906 commit cded444

File tree

5 files changed

+52
-1
lines changed

5 files changed

+52
-1
lines changed

2023/04/python_chain_nested_exception.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ AssertionError
2525

2626
cause 和 context 都是上一个 Exception 的引用(类比成链表的 next 字段)
2727

28-
PEP 上说 raise..from 是显示的连锁异常,多层嵌套是隐式的
28+
PEP 上说 raise..from 是显式的连锁(多层嵌套)异常(`__cause__`),一般的异常是隐式的连锁嵌套(`__context__`)
2929

3030
对使用者而言二者区别就错误提示文案不同
3131

2023/09/bst_chip_arm_linux_cross_compile.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,10 @@ Copysudo rm /var/lock/LCK..ttyUSB0
301301
|adb logcat|exec: logcat command not found|
302302
|adb shell screencap|screencap command not found|
303303

304+
adb shell 可以直接进嵌入式系统的 shell
305+
306+
试试 adb shell reboot 可以重启嵌入式系统,所以说写个脚本 adb push + adb shell reboot 就能一键脚本替换内核并重启了
307+
304308
### USB 协议是个主从协议?
305309
USB协议也支持一种特殊的模式,即On-The-Go(OTG)模式。在OTG模式下,一个设备可以既充当主机又充当从设备
306310

2023/09/per_cpu.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,28 @@ OSTEP 第二种 per_cpu 的实现方法,如果已经知道处理器个数,
1313
- `/proc/<pid>/task/<tid>/status`
1414
- getcpu()
1515

16+
### Linux 内核没有 get_nprocs()
17+
18+
```
19+
一种方法是通过查看内核中的cpu_possible_map变量来获取处理器的数量。cpu_possible_map是一个位图,表示系统中可能存在的处理器编号。可以使用cpumask_weight函数来计算处理器位图中被置位的位数,从而获取处理器的数量。
20+
21+
另一种方法是通过遍历系统中的处理器拓扑结构来获取处理器的数量。内核中的cpu_possible数组保存了系统中拥有的所有处理器,可以通过遍历该数组来计数处理器的数量。
22+
```
23+
24+
还有一种办法,我看了别人的代码实现
25+
26+
> #define NR_CPUS CONFIG_NR_CPUS
27+
28+
```
29+
arch/ia64/kernel/setup.c
30+
31+
#ifdef CONFIG_SMP
32+
unsigned long __per_cpu_offset[NR_CPUS];
33+
EXPORT_SYMBOL(__per_cpu_offset);
34+
```
35+
36+
用 CONFIG_NR_CPUS 这个值也能获取
37+
1638
## arceos per_cpu 实现
1739

1840
<https://github.com/rcore-os/arceos/blob/main/crates/percpu/test_percpu.x>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
# [重新思考 try/Result](/2023/09/rethink_of_try_catch_and_result.md)
3+
4+
## Result<usize> 的不足
5+
6+
[v2ex 关于 Go/Rust 异常处理的撕逼](https://www.v2ex.com/t/712344)
7+
8+
> rust 的成功,也包含两种成功,一种表示 EOF,一种表示读了一些。rust 的失败,也不止一种失败,而且 Interrupted 是一种特殊的失败,它并不是真的失败,只是暂时的失败
9+
10+
在 Golang 中最后一次 Read() 可能返回 42,io.EOF 但是在 Rust 中需要两次 read() 一次返回 Ok(42) 第二次返回 Ok(0) 我觉得在 read 系统调用次数上应该是一样的,但看上去 Rust 似乎会多一次 std::io::Read::read 的函数调用
11+
12+
## Exception 跨线程问题
13+
14+
重看了 chenhao 极客时间专栏错误处理文章,例如函数 atoi 不会设置 errno 无法/难以得知调用是否成功使用要谨慎
15+
16+
复习下 Python 的 Exception 嵌套
17+
18+
> PEP 上说 raise..from 是显式的连锁(多层嵌套)异常(`__cause__`),一般的异常是隐式的连锁嵌套(`__context__`)
19+
20+
我更关心 C++/Java/Python 异步编程/多线程中如何实现当前线程 try-catch 其他线程的 Exception
21+
22+
> 在C++、Java和Python中,无法直接在一个线程中捕获另一个线程抛出的异常。需要通过一些通信机制获取异常
23+
24+
Java 可以 Thread.setDefaultUncaughtExceptionHandler

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
- [文章列表 - 吴翱翔的博客](/)
22
- [正在读的书](/books.md)
33
- **2023-09**
4+
- [重新思考 try/Result](/2023/09/rethink_of_try_catch_and_result.md)
45
- [web3 与量化](/2023/09/web3_and_quantitative_trading.md)
56
- [-fsanitize 检查越界](/2023/09/gcc_fsanitize_detect_index_out_of_range_error.md)
67
- [树莓派 UART 驱动](/2023/09/rpi_uart_driver.md)

0 commit comments

Comments
 (0)