25th San Diego C++ Meetup

The 25th Meetup of the San Diego C++ Group was held on April 27th, 2021 and featured guest speaker Jerry Wiltse from the Conan Package Manager Team. The recording and slides of the presentation can be found here.

How to implement a spinlock / event / semaphore

Multi-threading has been the theme of my previous two classes where I discussed thread-pools and producer-consumer queues. Let’s talk about the fundamental aspects of multi-threading and some of its most basic building blocks: spinlocks, automatic and manual events, and semaphores.In this week’s class I will show you how to implement these building blocks using only […]

How to implement a producer-consumer queue

During my most recent class I discussed implementations of simple, multi-threaded, producer-consumer queues: unbounded (can grow in size indefinitely) and bounded (can only grow to a certain size). In short: the unbounded queue will block consumers’ pop() calls if it happens to be empty until a producer pushes something onto it. Bounded queue will do […]

How to implement a thread pool

By popular demand, and at the request of my coworkers, this week’s class was about implementing a simple thread pool using only standard C++ components. It would have taken 1h-30m if I didn’t completely forget how to use a condition variable. It’s 2h long!Bad std::condition_variable.wait(...) predicate caused a deadlock and I spent 30 minutes trying […]

Light-weight RPC framework

During my latest mentoring session with coworkers I was asked to explain how modern RPC frameworks work under the hood. What better way to illustrate this than to build one from scratch using components I blogged about previously (event objects, serializer framework, and TCP sockets). Although not part of the video recording (which I will […]

Case insensitive string, etc

The question of case insensitive strings has been, and continues to be asked a lot, and equally many answers can be found all over the internet. The go-to solution is to create a char_traits policy class with eq, lt, and compare methods implemented using std::toupper before comparing characters, then instantiate std::basic_string with it using istring = std::basic_string<char, char_itraits<char>> This […]

Welcome, Kobi!

I would like to extend a warm welcome to fellow C++ enthusiast, and blog contributor, Kobi! Many of you know him from his Twitter account or as the organizer of San Diego C++ Meetup. We have been exchanging likes and occasional comments on Twitter ever since I started this blog. He has always been encouraging […]

Function alias vs Function pointer alias

Last weekend (4/4/2021) I was sitting down and working on my San Diego C++ agenda for the 25th upcoming session. One of things I really like presenting is few riddles from cppquiz.org I stumbled upon this one: https://cppquiz.org/quiz/question/227 . Simple and easy one. Here is the code in question: And the question is what is […]

std::deep_ptr

std::deep_ptr aka deep copying smart pointer has not yet been introduced to the STL though several C++ experts have proposed an implementation in the past. See n3339.pdf for one such proposal and a list of possible implementations. In this post I want to share my implementation of deep copying pointer I recently came up with. […]

San Diego C++ Meetup

San Diego C++ Meetup 25th meeting featuring JFrog and Conan! Agenda Welcome slides – goals we would like to achieve in San Diego C++ MeetupThis meeting – Hosting JFrog: Conan Package Manager for C++ in Practice If time permits:* Shout Out to a great C++ blog – “Vorbrodt’s C++ Blog”* 3 cppquiz questions* 2 years […]

Fun with TCP sockets

The purpose of this post is not to teach you about posix sockets; there’s plenty of that already. Instead I want to share two simple classes I implemented last night which encapsulate two types of tcp sockets: listening server socket and a client socket. These sockets as well as my recent serializer code will be […]

Better serializer

In my last post I described a light-weight serialization framework I recently implemented (video where I go over it in detail). After receiving great feedback from r/cpp I have implemented several improvements that were suggested to me: better unpack transform signature, safer unpacking code, unpack casting iterator just to name a few. The latest code […]

Light-weight serialization framework

UPDATE: Better serializer In my very first YouTube Channel video I discuss in detail the design of a serialization framework I came up with in response to a question I was recently asked. In this post I want to give a brief overview of how it works and how to get started using it. The […]

The future of C++

I hope the title of this post got your attention! What I really mean is the future direction of this blog… In 2019 I created 85 short articles, in 2020 I blogged only twice. The last 12 months have pulled my attention away from this site and toward mentoring other engineers at work by hosting […]

Make std::vector of T, efficiently

What I want to briefly talk about today is likely obvious to seasoned C++ programmers, but may be of benefit for the newcomers to the language and the STL: that is how to efficiently create std::vector of any number of elements of type T, whatever T may be. The code is short and sweet, so […]

Singleton Pattern

First things first: if you’re still reading this blog, thanks! I haven’t posted anything since last December; it has been a rough first half of the year: COVID-19, working from home, isolation, you know the deal, but I have not given up on blogging, just finding the time for it has been nearly impossible. I […]

std::unique_ptr, or how to express explicit ownership

When we talk about std::unique_ptr we must mention the idea of explicit resource ownership as well as the concept of a resource source and sink. By wrapping a pointer inside std::unique_ptr we state that whoever holds the std::unique_ptr owns the resource explicitly: has complete control over its lifetime. Prior to C++11 this was expressed using […]

When exactly does the std::shared_ptr take ownership?

In a post I wrote few days ago titled “A word on std::shared_ptr” I was mistakenly arguing that, should the std::shared_ptr fail to allocate its control block (where the reference count and other information is stored), the passed raw pointer would not be deleted. Example: auto p = std::shared_ptr<T>(new T); Here, if the allocation and construction of T succeeded, […]

In-depth look at C++ shared pointers

First, you should use std::make_shared (most of the time) to create shared pointers. It is optimized to perform only one allocation for both the reference count / control block and the object it holds. It is also safer to use std::make_shared in the presence of exceptions: some_function(std::shared_ptr<T>(new T), std::shared_ptr<T>(new T)); Prior to C++17, one of the possible orders […]