20241102
- Do
rust-analyzer: Reload workspace
when Rust autocomplete isn’t working
- What is the
Send
trait in Tokio?
- It has to do with the task scheduler and threads
- I think it defines what can be sent to different threads
- The Tokio runtime can move tasks between different threads at
await
- Holding a lock during an await ; how could it result in deadlock?
- Another task might require access to the mutex; but it can’t access it because whatever task is awaiting is still holding the lock. So while the other task is waiting to acquire the lock, the original task can’t release it.
- Task A acquires the lock
- Task A awaits
- Task B tries to acquire the lock
- Task B waits to acquire the lock
- Task A can’t release the lock
- Problem: want to run two concurrent client commands. One that gets the value, another that sets the value.
- Can’t use two separate clients because that means a connection per task.
- Can’t share the same client across tasks (without some extra code to implement copying)
- Why do you need to implement copying?
- Can’t lock the client behind a mutex because can’t use a mutex across await. (the client.get and client.set methods are async.)
- Message passing is similar in spirit to the failed mutex solution; it’s basically a babysitter for a mutex.
20241029
Syntax for concurrency passing
ch <- v // Send v to channel ch.
v := <-ch // Receive from ch, and
// assign value to v.
func sum(s []int, c chan int) {
sum := 0
for _, v := range s {
sum += v
}
c <- sum // send sum to c
}
func main() {
s := []int{7, 2, 8, -9, 4, 0}
c := make(chan int)
go sum(s[:len(s)/2], c)
go sum(s[len(s)/2:], c)
x, y := <-c, <-c // receive from c
fmt.Println(x, y, x+y)
}
20241026
https://www.youtube.com/watch?v=IroPQ150F6c&ab_channel=ChimiChanga
20241025
- rust ownership: tree-like. One thing can own a bunch of other things, but that one thing can have only 1 owner.
- rust move: instead of copying pointers (like Python or other assignment-cheap languages) or making copies outright (like C), Rust moves and invalidates the old. It’s a middle ground in the tradeoff of cheap assignment <> clear memory ownership.
20241023