# linux2023: 25077667 homework1 <contributor: `25077667`> Also known as scc. ## 開發過程 GitHub 我有在 GitHub 留下開發過程,但是好像現在不適合公開 [2023/08/10 02:48] https://github.com/25077667/linux-summar-2023 Anyway, I left a private repository here. :::warning 程式碼寫出來,就是要給人們使用和指教,何必孤芳自賞? :notes: jserv ::: :::info I opened it. ::: :::spoiler 明天睡醒再寫詳細資料 ::: ## $\alpha$ ```shell ➜ linux-summar-2023 git:(master) ✗ cc test1/stree.c -fsanitize=address -g ➜ linux-summar-2023 git:(master) ✗ ./a.out [ After insertions ] 0 4 5 6 7 8 10 13 16 17 18 19 21 25 26 27 30 31 33 35 36 39 42 44 45 47 49 50 51 55 56 57 58 59 60 61 62 63 64 65 68 69 71 72 73 77 78 80 81 82 86 88 89 90 91 92 94 95 96 97 98 Removing... 70 94 79 46 73 96 28 65 49 71 19 58 72 16 21 78 61 84 49 66 55 93 78 96 97 98 48 41 62 86 33 26 88 32 23 4 71 48 64 44 45 92 33 61 27 44 50 85 82 52 56 28 65 60 9 65 28 93 9 89 76 93 28 80 6 60 22 19 95 12 35 93 60 84 69 47 44 92 11 40 60 32 81 31 56 71 19 43 52 11 38 6 79 59 74 53 8 80 55 28 [ After removals ] 57 ➜ linux-summar-2023 git:(master) ✗ ``` 這邊我對我的答案還挺有信心的,我想了一陣子,不會是假解才對 同時,我也使用 address sanitizer 協助驗證,沒有踩到 shadow memory 這邊也不會有 unalignment issue (ASAN 唯一可能的 False negative),理應不會有非法記憶體存取 我想明天上課再聽老師講解 ## $\beta$ 這題是考古題,以前有寫過類似,因為以前有想過,所以這次不會想太久 ## $\gamma$ 我把 goto label 重命名之後,就可以清楚了解這邊的運作 所以根據對稱性,就可以很容易推算出答案 至於 data race,很慶幸以前我有研究過 TSAN TTSAN 打開,看到 211 322 351 343 產生 race 進去看是在變更 thread state 的地方 產生 data race 而 thread state 這邊是 enum 根據 C17 語言標準 6.2.5 第 17 點 ```text The type char, the signed and unsigned integer types, and the enumerated types are collectively called integer types. The integer and real floating types are collectively called real types. ``` **the enumerated types** 就是 int type ,所以可以直接使用 C11 標準的 `_Atomic` > 幾年前有研究過 C++ 的 std::atomic<T> 需要 std::is_trivially_constructable<T> 因此腦袋想一想 compiler 會如何 reg alloc ,因此這邊可以使用 _Atomic 使得 compiler 能產生 xchg 之類的 inst. 如何 reg alloc 是我最近讀 clang 資料 [Creating an LLVM Backend for the Cpu0 Architecture](http://jonathan2251.github.io/lbd/index.html) 學習的,值得留意的是這篇 [Creating an LLVM Backend for the Cpu0 Architecture](http://jonathan2251.github.io/lbd/index.html) 作者是台灣人!! [陳鍾樞](https://jonathan2251.github.io/ws/ch1/resume_cschen.html)前輩 reg alloc 細節: :::spoiler 待捕 :::