Jeffrey.W

@butastur

Joined on Jun 19, 2018

  • contributed by < jserv, jeffrey.w > Arm 工程師 Will Deacon 在 Edinburgh 的演講 Uh-oh; it's I/O ordering 中提到一個範例: 初始條件:*x, *y 在記憶體裡,初始值為 0,foo, bar 是 local variable digraph g { rankdir = "RL"; "cpu0" [label= "CPU0 | a: WRITE_ONCE(*x, 1); | b: foo = READ_ONCE(*y);", shape="record"];
     Like 10 Bookmark
  • contributed by < jeffrey.w > Introduction C 語言在 C99 的時候還沒有將並行 (concurrency) 納入到語言的標準,但到了C11 standard 就開始將並行、memory order 相關的機制加入到規格裡,本文將透過學習 C11 standard 和 C++11 standard 來理解並行在語言層面的機制,然後使用 C11 來實驗並行。 Modification order §5.1.2.4/7 定義了 modification order All modifications to a particular atomic object M occur in some particular total order, called the modification order of M. If A and B are modifications of an atomic object M, and A happens before B, then A shall precede B in the modification order of M...
     Like  Bookmark
  • contributed by < jeffrey.w > 這篇筆記回顧我 2001 年剛學 design patterns 的時候對 strategy pattern 的誤解,透過重新審視 2001 那年的誤解,重新學習 strategy pattern。 Strategy pattern 很容易跟 template method pattern 混淆,2001 年我剛學這兩種 pattern 的時候,甚至直接誤以為「把實作碼寫在 base class 讓 derived class 繼承就是 design pattern」,當年我真是完全誤解了 strategy pattern 和 template method pattern 在設計上的初衷。 先舉一個跟 design pattern 完全沒有關係 的例子,但我在 2001 年卻曾經把這個例子誤會成 design pattern。 以下這個例子和 design pattern 沒有任何關係
     Like 5 Bookmark
  • contributed by < jeffrey.w > Introduction Java 1.8 新增了幾個 feature,其中一些對於提升程式可讀性很有幫助,例如 stream, lambda expression, method references 和 functional interface。 stream operations 會組成一個 stream pipeline,stream pipeline 包含了一個 source、零個或一個以上的 intermediate operations (例如 filter),還有一個 terminal operation (例如 forEach) [1]。 Intermediate operations intermediate operations 是指像 filter、map、distinct 之類的 method,這些 method 會將一個 stream 轉換成另一個 stream [1]。
     Like  Bookmark
  • contributed by < jeffrey.w > Template metaprogramming (TMP) 是一種從 template 的角度開發的 paradigm,也就是說他不是著眼在 int 或是 float 這種特定的 type,而是著眼在形而上的 type。原本我想用 concept 或是 generic 來說明,但由於 concept 和 generic 在 C++ 另有其他的解釋,為避免混淆,所以這裡不會提到 concept 和 generic。 C++11 從規格定義了 template,是學習 template 相當有用的第一手資料。本文是透過規格書學習 templates 的筆記,範圍包含 constexpr、type traits、partial specializations和template constructor,並且對於 compiler 在編譯時產生的 error 給出規格書上的解釋。 :::info 透過這份文件 N3377=12-0067,可以知道 N3376 是最接近 C++11 規格的草案,所以這份筆記主要是以 N3376 為主。 :::
     Like 2 Bookmark
  • contributed by < jeffrey.w > Introduction 本文將參考 Michael & Scott algorithm,以 C11 規格 [1] 實作 non-blocking concurrent queue。 Non-blocking singly-linked list 由於 Michael & Scott algorithm 是使用 singly-linked list 實作 non-blocking concurrent queue,所以本文會先實驗如何實作一個 non-blocking singly-linked list,重點會放在 concurrent insertion。 關於 concurrent linked list,2001 年 Harris 提出一個 non-blocking 的 solution [2],這個 solution 使用了 compare-and-swap 來完成。
     Like  Bookmark
  • contributed by < jeffrey.w > Background 有什麼方法可以對一個物件的 property 指定不同的 value,卻不用修改 程式?當我們在實作 function 的時候還不知道某一個物件的值是什麼,有什麼方法可以把「指定一個特定的值」這件事放在 source code 的外部?有什麼方法可以「不用修改程式就能把某一個變數所 reference 到的物件換成另一份 implementation」? 這個時候就可以使用 IoC (Inversion of Control) 了,而實現 IoC 的方式之一就是 DI (Dependency Injection)。透過 DI,當需要指定不同的值給 property 或是使用不同的 implementation 的時候,就不用對 source code 重新 compile,只需要更改依賴注入就可以注入不一樣的 implementation 和 property。 BeanFactory 在寫這段 code 的時候,還不知道 cpu.printVendor(); 會印出什麼,但是可以 從外部提供一個 implementation,而不用修改 source code,這個從外部提供的動作就是依賴注入 Dependency Injection。
     Like  Bookmark
  • # Template metaprogramming 學習筆記 ###### tags: `template metaprogramming` `c++11` `template specialization` `partial specialization` ## Introduction 這裡嘗試從 C++11 規格來學習 Template metaprogramming。<sub>(Template metaprogramming 並不是只能在 C\++ 中實現)</sub> ## struct template [C++11, 21.2 Character traits](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3376.pdf#section.21.2) 提到了一個 `struct template` 和 4 個相關的 `explicit specializations`,`char_traits<char>`、`char_traits<char16_t>`、`char_traits<char32
     Like 2 Bookmark