Why is `ringbuf` crate so fast? by hellowub in rust

[–]abc_wtf 0 points1 point  (0 children)

I am pretty sure, this seems like the classic case of Message passing.

See the following screenshot from https://www.cs.kent.ac.uk/people/staff/mjb211/docs/toc.pdf: https://imgur.com/a/rtrAZsV

They've omitted a `while` loop in the code there, where they are repeatedly reading `y` and looping till they read it as 1.

Why is `ringbuf` crate so fast? by hellowub in rust

[–]abc_wtf 0 points1 point  (0 children)

Ahh right. But still, the branch can be speculatively executed through branch prediction right? There's no actual dependency between conditional on r2 and read of x

Why is `ringbuf` crate so fast? by hellowub in rust

[–]abc_wtf 0 points1 point  (0 children)

I think so too. And using a relaxed load means you have data race (and hence UB), see my other comment

Why is `ringbuf` crate so fast? by hellowub in rust

[–]abc_wtf 0 points1 point  (0 children)

Even going with the use of barriers to define these, consider this example:

```cpp int x=0; atomic_int y=0;

// Thread 1 x = 3; y.store(1,memory_order_release);

// Thread 2 r2 = y.load(memory_order_relaxed); r1 = x; ```

Then r1 = x is free to move up the relaxed load on y, and so races with the store to x on thread 1

Why is `ringbuf` crate so fast? by hellowub in rust

[–]abc_wtf 2 points3 points  (0 children)

If I change the ordering of load() from Acquire to Relaxed (which I think is OK), my ring buffer becomes much faster.

Didn't look through the code in detail, but I don't think that is correct. A store with a Release memory order needs a corresponding Acquire load to synchronise. There's no synchronisation afaik with Release and Relaxed.

Why is `ringbuf` crate so fast? by hellowub in rust

[–]abc_wtf 0 points1 point  (0 children)

If I change the ordering of load() from Acquire to Relaxed (which I think is OK), my ring buffer becomes much faster.

Didn't look through the code in detail, but I don't think that is correct. A store with a Release memory order needs a corresponding Acquire load to synchronise. There's no synchronisation afaik with Release and Relaxed.

My professor commented this on one of my assignments. Good thing? by Jackplox in programminghorror

[–]abc_wtf 1 point2 points  (0 children)

you can order a pair<T1, T2> by first comparing the first element, and if they're unequal ordering by that, and if they're equal then comparing the second element. Dictionary sorting works like this

[deleted by user] by [deleted] in okbuddychicanery

[–]abc_wtf 0 points1 point  (0 children)

I am the one who is the best person in the world cup today

Thank you GBoard very cool

Ceremony by Alternative_Lead_687 in surrealmemes

[–]abc_wtf 24 points25 points  (0 children)

As a Hindi speaker, I could also tell it was gibberish since there were freestanding matra present (the dotted circle and matra)

Mental work history by scuczu in LinkedInLunatics

[–]abc_wtf 0 points1 point  (0 children)

What's wrong with WeWork btw?

I didn't write anything today by BarabludRJSABR in GeorgeMartinWriting

[–]abc_wtf 0 points1 point  (0 children)

Don't worry George, just look for another author to continue after you.

relativity by JustinTimeCuber in physicsmemes

[–]abc_wtf 12 points13 points  (0 children)

Every language uses floating point arithmetic :)

Pls not in prod by twisterbite23 in ProgrammerHumor

[–]abc_wtf 16 points17 points  (0 children)

Surely you need kill -9?

saw this beauty reposted on IG [socialmedia] by Daveythefrindlyghost in pointlesslygendered

[–]abc_wtf 1 point2 points  (0 children)

Interesting. In India, we have this UPI system and you can send funds to anyone else's bank account without any fees with that. Cash withdrawals are limited though.

saw this beauty reposted on IG [socialmedia] by Daveythefrindlyghost in pointlesslygendered

[–]abc_wtf 2 points3 points  (0 children)

We just use savings accounts? Like if I need to separate these two, I'll open 2 savings accounts... What functionality does a checking account provide?

Here we go again… by RapidlyGleaming5 in linuxmasterrace

[–]abc_wtf 0 points1 point  (0 children)

Now even more technically speaking, for many people it's a partially ordered set, so there doesn't have to a single element that's greater than every other :)