Skip to content

Instantly share code, notes, and snippets.

View RedBeard0531's full-sized avatar

Mathias Stearn RedBeard0531

View GitHub Profile
@RedBeard0531
RedBeard0531 / tcmalloc_rseq_fixes.patch
Created April 22, 2026 07:31
tcmalloc rseq fixes for linux 6.19
diff --git a/tcmalloc/cpu_cache.h b/tcmalloc/cpu_cache.h
index 3ea24065168..a460ebb5227 100644
--- a/tcmalloc/cpu_cache.h
+++ b/tcmalloc/cpu_cache.h
@@ -726,12 +726,12 @@ static cpu_set_t FillActiveCpuMask() {
}
#ifdef PERCPU_USE_RSEQ
- const bool real_cpus = !subtle::percpu::UsingFlatVirtualCpus();
+ constexpr bool real_cpus = !subtle::percpu::UsingFlatVirtualCpus();
{"timestamp":"2025-06-25T10:33:42.683324Z","level":"INFO","fields":{"message":"logging initialised"},"target":"watchexec_cli::args::logging"}
{"timestamp":"2025-06-25T10:33:42.683400Z","level":"INFO","fields":{"message":"effective working directory","path":"\"/tmp/root\""},"target":"watchexec_cli::args::command"}
{"timestamp":"2025-06-25T10:33:42.683484Z","level":"DEBUG","fields":{"message":"home directory","homedir":"Some(\"/home/mstearn\")"},"target":"watchexec_cli::dirs"}
{"timestamp":"2025-06-25T10:33:42.683498Z","level":"DEBUG","fields":{"message":"resolved whether the homedir is explicitly requested","homedir_requested":"false"},"target":"watchexec_cli::dirs"}
{"timestamp":"2025-06-25T10:33:42.683517Z","level":"DEBUG","fields":{"message":"no origins, using current directory"},"target":"watchexec_cli::dirs"}
{"timestamp":"2025-06-25T10:33:42.683532Z","level":"DEBUG","fields":{"message":"resolved all project origins","origins":"{\"/tmp/root\"}"},"target":"watchexec_cli::dirs"}
{"timestamp":"2025-06-25T10:
# This was created by cxx_modules_builder. DO NOT EDIT.
MAKE_NINJA = /home/mstearn/opensource/cxx_modules_builder/modules_builder.py
CXX = /usr/sbin/clang++
# START HEADER
COMMONFLAGS = -stdlib=libc++ -pthread
DEBUGFLAGS = -ggdb3 -gsplit-dwarf
CXXFLAGS = -fcolor-diagnostics -fPIC -Isrc -Ibuild/src -Isrc/external/pegtl/include/tao/ -std=c++2a -DREALM_DEBUG=1 $COMMONFLAGS $DEBUGFLAGS
LIBS = -lcrypto -lc++experimental
LINKFLAGS = -fuse-ld=lld $COMMONFLAGS
@RedBeard0531
RedBeard0531 / cpp17.md
Last active September 21, 2022 03:50
New C++17 features

Supplement to this video. Watch first 35 min (the language bits), then 1:14:30 - 1:18:15 (the new map features).

You can find a fairly comprehensive list of new features on cppreference or here if you really want to see it all.

Recap of features described in the video

@RedBeard0531
RedBeard0531 / generator.h
Created September 14, 2021 12:59
C++20 generator with nice semantics for simple generator<T>
#pragma once
#include <iterator>
#include <utility>
#include <coroutine>
// Only need one of these. Shouldn't depend on generator's T.
struct generator_sentinel {};
template <typename T>
@RedBeard0531
RedBeard0531 / functions.js
Created February 22, 2012 20:13
Min, Max, Sum, Count, Avg, and Std deviation using MongoDB MapReduce
// derived from http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Parallel_algorithm
function map() {
emit(1, // Or put a GROUP BY key here
{sum: this.value, // the field you want stats for
min: this.value,
max: this.value,
count:1,
diff: 0, // M2,n: sum((val-mean)^2)
});
-------------------------------- MODULE OT --------------------------------
EXTENDS Integers, TLC, FiniteSets, Sequences
CONSTANTS i_set, i_inc, i_nop \* Instruction model values
CONSTANT NULL
CONSTANT ImprovedAlgo
ASSUME ImprovedAlgo \in BOOLEAN
@RedBeard0531
RedBeard0531 / mod_reach.cpp
Created November 7, 2019 13:39
module reachability examples
export module quux;
export struct quux{};
///////////
// bar.h
import quux
/////////
clang++ -std=c++2a -x c++-module iface.cpp --precompile -o iface.pcm -stdlib=libc++
clang++ -std=c++2a -x c++ consumer.cpp -c -o consumer.o -fmodule-file=iface.pcm -stdlib=libc++
echo <<OUTPUT
In file included from consumer.cpp:2:
In file included from /usr/include/c++/v1/string:505:
In file included from /usr/include/c++/v1/string_view:176:
In file included from /usr/include/c++/v1/__string:57:
In file included from /usr/include/c++/v1/algorithm:643:
/usr/include/c++/v1/utility:574:1: error: redeclaration of deduction guide
@RedBeard0531
RedBeard0531 / sc.cpp
Created March 14, 2019 18:45
Example of non-sequential consistency
// {{{
// vim: set foldmethod=marker:
// g++ -O3 -pthread sc.cpp && ./a.out
#include <cstdio>
#include <thread>
#include <atomic>
using namespace std;
constexpr auto load_order = memory_order_acquire;
constexpr auto store_order = memory_order_release;