A `compare-and-exchange` loop is the most common way to implement atomic operations.
x86 systems provide an instruction prefix called `lock` as a modifier to make instructions like `add` atomic.
A `Weak<T>` aka. weak pointer provides a solution for dropping cyclic structure
Arc is basically a pointer to a shared `ArcData<T>` object.
Target: Create a blocking channel
Better performance means less convenience and simplicity. It is just a trade-off.
An Extension of the previous Record: An Unsafe One-Shot Channel, Safety Through Runtime Checks
An Extension of the previous paragraph: An Unsafe One-Shot Channel
Function of One-Shot Channel: Send 'exactly one' message from one thread to another.
A `Mutex` is very similar to `RwLock`, but it only allows exclusive borrows
`std::cell::Cell<T>`, `std::cell::RefCell`
Function of Channel: Send data from one thread to another
When data is mutated by multiple threads, there are many situations where they would need to wait for some event, for some condition about the data to become true.
常用的 SQL 語法
SQL 是宣告式語言
E-commerce, Banking System, Airline Reservation System, ...
Nature Key vs Surrogate Key
Even if a file is only 1 bytes, it will still occupy 4 KB of space at file system based on 4 KB block size
4 levels: Read Uncommitted, Read Committed, Repeatable Read, Serializable
用途: 達到 isoliation 避免 race condition
Three types: dirty read, non-reapeatable read, phantom read
In most use cases, A spin lock will be used to protect mutations to a shared variable
正規化的基礎訓練,能讓你設計系統時能跟蹤前人的智慧,而不是自行發明看起來沒問題的演算法
對一般中小型系統, RDBMS 效能足夠了
對一般中小型系統, RDBMS 效能足夠了
Instead of putting the thread to sleep, the thread will continuously attempt to lock the locked lock
In addition to memory operations on atomic variables, memory ordering can also be applied to atomic fences in concurrent programming
Each operation using SeqCst memory ordering contributes to a global order in which all operations are arranged
no compiler actually implements consume ordering
Target: to form a happens-before relationship between threads
Compare-and-Exchange checks if the atomic value is equal to a given value, and only if that is the case does it replace it with a new value
Some common use cases: a stop flag, process reporting
one thing is guaranteed to happen before another thing
Processors and compilers perform all sorts of tricks to make your programs run as fast as possible
These operations modify the atomic variable, but also load (fetch) the original value, as a single atomic operation.
Atomic operations allow for different threads to safely read and modify the same variable
A reader-writer understands the difference between exclusive and shared access, and can provide either.
A Mutex in Rust gets marked as poisoned when a thread panics while holding the lock.
While using a mutex can ensure serialized execution, it also negates the advantages of parallelism
在具有多帳戶功能的系統中,一個 User 可以有多個 Account ,而在 Account table 中又可以儲存多種幣別 (USD, NTD…) 。我們可以利用 `composite index` 加上 `unique` 的特性, 令 User 避免持有相同的幣別的 Account
Interior mutability only bends the rules of shared borrowing to allow mutation when shared
Immutable borrowing(&) + Mutable borrowing(&mut) = fully prevent data races
Some ways to share ownership to threads: `static`, `Box::leak(Box::new([1, 2, 3]));`, `Arc`
std::thread::scope spawn scoped threads => possible to safely borrow local variables. eg:
Polymorphism 的目的? 藉由 Polymorphism 使 code 更加靈活、reusable、易擴展和可維護
某天在使用 Golang 的時候,突然發現原來 Golang 沒有像其他語言一樣有實作 Set 的 data structure,稍微爬了文後發現,原來 Golang 會用 map 來模擬 Set ,以下是僅是小小的紀錄。
The `std::thread::spawn` function is actually just a convenient shorthand for `std::thread::Builder::new().spawn().unwrap()