|
1 | 1 | #+TITLE: 202405
|
2 |
| -#+DATE: 2024-05-02T22:18:59+0800 |
3 |
| -#+LASTMOD: 2024-05-06T09:35:39+0800 |
4 |
| -#+DRAFT: true |
5 |
| -* 重大事件 |
| 2 | +#+DATE: 2024-06-02T22:18:59+0800 |
| 3 | +#+LASTMOD: 2024-06-03T23:05:49+0800 |
| 4 | + |
6 | 5 | * 观点/教程
|
7 |
| -- [[https://arne.me/blog/thoughts-on-zig][Thoughts on Zig]] :: 又一篇 Zig 初学者的使用体验文档,如果你也在犹豫要不要学 Zig,这是个不错的经验参考。 |
8 |
| -- [[https://www.reddit.com/r/Zig/comments/1ckstjv/im_sold_on_zigs_simplicity/][I'm sold on Zig's simplicity : r/Zig]] :: 一个具有资深经验开发者,在这里描述了自己选择业余项目语言的经历: |
| 6 | +** [[https://arne.me/blog/thoughts-on-zig][Thoughts on Zig]] |
| 7 | +又一篇 Zig 初学者的使用体验文档,如果你也在犹豫要不要学 Zig,这是个不错的经验参考。 |
| 8 | +** [[https://www.reddit.com/r/Zig/comments/1ckstjv/im_sold_on_zigs_simplicity/][I'm sold on Zig's simplicity : r/Zig]] |
| 9 | +一个具有资深经验开发者,在这里描述了自己选择业余项目语言的经历: |
9 | 10 | - Rust 越来越复杂,有种发展成 C++ 的趋势
|
10 | 11 | - C++ 新版本的特性(比如 module)LSP 支持的不够好,而且历史包袱严重
|
11 | 12 | - C 缺少元编程,并且没有命名空间
|
|
16 | 17 | - 与 C 无缝交换,
|
17 | 18 | - 具有 Result 效果的错误处理
|
18 | 19 | - 唯一缺失的就是『接口』,但这一点并不是很关键,就像在 C里也没有,但是 C 可以做任何事
|
| 20 | +* [[https://andrewkelley.me/post/zig-new-cli-progress-bar-explained.html][Zig's New CLI Progress Bar Explained]] |
| 21 | +Andrew 的一篇文章,讲述了在最新版的 Zig 中,对进度条的改进实现,现在的进度展示更加友好。 |
| 22 | + |
| 23 | +实现的难点在于在多线程环境下,如何保证高性能,文章中大致讲述了其实现: |
| 24 | +- 首先通过预先分配好需要使用的结构,保证后续无需在进行 heap 申请 |
| 25 | +- 通过 atomic 操作来实现一个无锁的 freelist,用于申请、释放 Node |
| 26 | +* [[https://www.openmymind.net/Writing-a-Task-Scheduler-in-Zig/][Writing a task scheduler in Zig]] |
| 27 | +Openmymind 作者的又一力作,通过编写一个任务调度器,讲述了多线程编程的基本要领: |
| 28 | +- 共享的数据要加锁 |
| 29 | +- 条件变量要和锁一起使用,会有[[https://en.wikipedia.org/wiki/Spurious_wakeup][惊群效应]],因此在被唤醒时,需要重新检查状态是否正确。 |
| 30 | + #+begin_src zig |
| 31 | +fn run(self: *Self) void { |
| 32 | + while (true) { |
| 33 | + self.mutex.lock(); |
| 34 | + while (self.queue.peek() == null) { |
| 35 | + self.cond.wait(&self.mutex); |
| 36 | + } |
| 37 | + // TODO |
| 38 | + } |
| 39 | +} |
| 40 | + #+end_src |
| 41 | + 它会在 wait 前释放锁,在 wait 返回时先加锁,类似下面的实现: |
| 42 | + #+begin_src zig |
| 43 | +fn wait(c: *std.Thread.Condition, mutex: *std.Thread.Mutex) void { |
| 44 | + // do some setup |
| 45 | + // ... |
| 46 | + |
| 47 | + mutex.unlock(); |
| 48 | + |
| 49 | + // whatever happens, we'll always return with this locked |
| 50 | + defer mutex.lock(); |
| 51 | + |
| 52 | + // wait for signal |
| 53 | + // or timeout if calling timedWait |
| 54 | + // ... |
| 55 | +} |
| 56 | + #+end_src |
19 | 57 | * 项目/工具
|
| 58 | +- [[https://github.com/chung-leong/zigar][zigar]] :: Enable the use of Zig code in JavaScript project。它可以让你直接在 JS 中调用 zig 代码,背后原理是编译成了 wasm 实现的。 |
| 59 | +- [[https://github.com/srijan-paul/nez][srijan-paul/nez]] :: An emulator for the NES console. |
| 60 | +- [[https://github.com/deckarep/ziglang-set][deckarep/ziglang-set]] :: A generic and general purpose Set implementation for the Zig language |
| 61 | +- [[https://github.com/akarpovskii/tuile][akarpovskii/tuile]] :: A Text UI library for Zig |
| 62 | + |
20 | 63 | * [[https://github.com/ziglang/zig/pulls?page=1&q=+is%3Aclosed+is%3Apr+closed%3A2024-05-01..2024-06-01][Zig 语言更新]]
|
0 commit comments