RSSAmplifier

Blog

Lu’s blog

Learnings on system and programming.

/RSS feed ↗10 posts

Latest posts

Atomic Queue

This post is about folly’s AtomicQueue. It is a lock-free MPSC(multiple-producer-single-consumer) queue that only wakes up the consumer when necessary. It is mainly used as the notification queue for folly::EventBase, as a way to pass work from external threads to be executed on the EventBase thread. In this context, the EventBase is the consumer, and it always runs on the same thread. There can…

Integer Division in Bucketed Time Series

This post is about a cool piece of integer math code in folly::BucketedTimeSeries.

A Mental Model for C++ Coroutine

C++ coroutine is not a library that is ready to go (e.g. std::vector). It is not even a trait (think of Rust’s Future trait) that library writers or users can implement (or the compiler generates for you in the case of Rust). C++ coroutine is a specification that defines a set of customization points that library writers implement in order to get a functional coroutine.

Access a function’s return value in C++ scope guard

It is best to avoid accessing a function’s return value in a scope guard or we need to be really careful about the return value’s lifetime.

When `__cxa_pure_virtual` is just a different flavor of SEGFAULT

A program crashed during shutdown, with message pure virtual method called which came from __cxa_pure_virtual – where a pure virtual function points to, in its vtable. Its implementation involves calling std::terminate which calls std::abort which by default throws a SIGABRT, and crashing the program. Now, why did pure virtual method got called?

Rust’s early vs. late lifetime binding

Lifetime in many ways are similar to types but also different. The goal of this post is to explain my mental model of rust’s lifetime binding works, when it takes place, and a trick to force late lifetime binding when needed.

zsh interprets a standalone redirect as a `cat` command

I use zsh and yesterday I was testing a program with myprogram 2>/dev/null. In one iteration, I accidentally copied a newline character after the myprogram command and the zsh prompt looked something like

C++ coroutine and lambda’s lifetime

We rarely need to worry about lambda’s lifetime more than any other objects in C++ until we are dealing with coroutine at the same time. folly’s wiki has a good example of why we need to be careful about lambda’s lifetime – https://github.com/facebook/folly/blob/main/folly/experimental/coro/README.md#lambdas. The tl;dr is that when you have a lambda that returns a coroutine handle, we need to make…

`folly::IOBuf` and zero-copy networking

I see folly::IOBuf often used as a return value (sub-)type in RPC definitions for data intensive and high performance applications. I looked at the code, and it says

What I learned about `inline` recently

C++’s inline is pretty nice, in my opinion. I define an inline function with external linkage, things work as expected (https://en.cppreference.com/w/cpp/language/inline):