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…
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.
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?
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.
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
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…
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
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):