Skip to content

Commit

Permalink
dump
Browse files Browse the repository at this point in the history
Signed-off-by: Haile Lagi <[email protected]>
  • Loading branch information
hailelagi committed Nov 30, 2024
1 parent 13a23e8 commit 08ba183
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
31 changes: 31 additions & 0 deletions content/notes/atomics.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ draft: true
Typically a compiler intrinsic, platform/hardware dependent(x86, risc-v, arm etc), OS dependent.
Typically at least a pointer size -- in rust a [`usize`](https://doc.rust-lang.org/std/primitive.usize.html)

## Orderings
- Relaxed: total modification order
- Release & Acquire: happens-before btw thread A & B

> A happens-before relationship is formed when an acquire-load operation observes the result of a release-store operation. In this case, the store and everything before it, happened before the load and everything after it.
- AcqRel, SeqCst:
- *Consume

## Load and Store

```rust
Expand Down Expand Up @@ -89,8 +98,30 @@ fn increment(a: &AtomicU32) {
```

## Locks - Mutexes/ RwLock etc

design axis:
- fairness (FIFO)
- correctness (mutual exlusion)
- performance (syscall overhead, space etc)
- priority inversion

mutex lock/unlock atomic:
```rust
use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering::{Acquire, Relaxed, Release};
use std::thread;

static mut DATA: String = String::new();
static LOCKED: AtomicBool = AtomicBool::new(false);

fn mu() {
if LOCKED
.compare_exchange(false, true, Acquire, Relaxed)
.is_ok()
{
// Safety: We hold the exclusive lock, so nothing else is accessing DATA.
unsafe { DATA.push('!') };
LOCKED.store(false, Release);
}
}
```
11 changes: 11 additions & 0 deletions content/notes/compiler-optimisations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
title: "Compiler Optimisations"
date: 2024-11-29T19:43:18+01:00
draft: true
---

Mental Check List of Compiler Optimisations that leak implementation details:
- jumping and branching
- loop unrolling
- Constant folding and constant propagation
- common subexpresssion elimination
5 changes: 3 additions & 2 deletions content/notes/cpp-weirdness.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ date: 2024-10-23T13:09:40+01:00
draft: true
---

fun facts:
"fun" c++ "facts":
- multiple inheritance
- https://en.wikipedia.org/wiki/Copy_elision
- https://eli.thegreenplace.net/2012/06/28/the-type-variable-name-ambiguity-in-c
- https://en.wikipedia.org/wiki/Most_vexing_parse

- the thin-air problem: https://www.cl.cam.ac.uk/~pes20/cpp/notes42.html
- Curiously recurring templates: https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern

things I don't like:
~~syntax ambiguity~~ not that bad
Expand Down

0 comments on commit 08ba183

Please sign in to comment.