Skip to content

Instantly share code, notes, and snippets.

cmake_minimum_required(VERSION 3.12)
# A reproduction of the example given in
# https://cmake.org/cmake/help/latest/command/target_link_libraries.html#linking-object-libraries
project(CMakeTest)
# Object Libraries may be used as the <target> (first) argument of target_link_libraries to specify dependencies of their sources on other libraries. For example, the code
add_library(A SHARED a.c)
target_compile_definitions(A PUBLIC A)
import collections
horiz_edges = [
[">", "<", ">", ">"],
["<", " ", "<", ">"],
[">", ">", "<", " "],
["<", " ", ">", "<"],
[" ", " ", ">", ">"],
]
assert len(horiz_edges) == 5
use rayon::prelude::*;
use std::io::BufRead;
fn edit_distance(s1: &str, s2: &str) -> usize {
if s1.len() > s2.len() {
return edit_distance(s2, s1);
}
let mut distances: Vec<usize> = (0..=s1.len()).collect();
for (i2, c2) in s2.chars().enumerate() {
@jthemphill
jthemphill / debugging.md
Created November 4, 2021 20:07
HHVM watchman deadlock GDB debugging session

Summary

  • The thread that holds s_sharedDataMutex is calling WatchmanConnection::close()
  • WatchmanConnection::close() needs to run something in the EventBaseThread
  • The EventBaseThread is in a callback that's trying to get s_sharedDataMutex
  • This is a deadlock.

Event Base Thread

@jthemphill
jthemphill / gist:487b41c21c35fa026f71fe82939d0413
Created November 4, 2021 20:07
HHVM watchman deadlock quickstack
2021-11-02 13:41:47 837839: Setting mount namespace failed. Errno: 22
2021-11-02 13:41:47 837906: Target pid: 425995 (inside container: 425995)
2021-11-02 13:41:47 841508: Reading process symbols..
2021-11-02 13:41:48 189050: Gathering stack traces..
2021-11-02 13:41:48 233281: Printing stack traces..
2021-11-02 13:41:48 233298: Total Traced Time: 35.196 milliseconds
2021-11-02 13:41:48 233306: Average Traced Time Per LWP: 0.109 milliseconds
2021-11-02 13:41:48 233310: Longest Traced LWP: LWP 4047257, 0.528 milliseconds
Thread 323 (LWP 4122695):
@jthemphill
jthemphill / facts.tla
Created March 22, 2021 21:33
TLA+ spec for HHVM's live type-to-file reverse index
------------------------------- MODULE facts -------------------------------
EXTENDS Integers
CONSTANTS
NumFiles,
NumTypes,
NumRequests,
FinalClock
// % g++ --std=c++14 accidentalcopy.cc -o accidentalcopy
// % ./accidentalcopy
// This prints the output:
//
// 42 = 42
// 42 = 42
// accidentalcopy(13656,0x117fc45c0) malloc: *** error for object 0x7fd967402b20: pointer being freed was not allocated
// accidentalcopy(13656,0x117fc45c0) malloc: *** set a breakpoint in malloc_error_break to debug
#include <iostream>
.section __TEXT,__text,regular,pure_instructions
.globl __ZN10slow_iters5tests8iter_any17h9958878595c8e553E
.p2align 4, 0x90
__ZN10slow_iters5tests8iter_any17h9958878595c8e553E:
.cfi_startproc
pushq %rbp
Lcfi0:
.cfi_def_cfa_offset 16
Lcfi1:
.cfi_offset %rbp, -16
// WARNING: This output format is intended for human consumers only
// and is subject to change without notice. Knock yourself out.
fn tests::iter_any::{{closure}}(_1: &mut [closure@src/lib.rs:4:24: 4:35], _2: &i32) -> bool {
let mut _0: bool; // return pointer
scope 1 {
let _3: i32; // "x" in scope 1 at src/lib.rs:4:26: 4:27
}
let mut _4: i32;
bb0: {
; ModuleID = 'slow_iters.cgu-0.rs'
source_filename = "slow_iters.cgu-0.rs"
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-darwin"
%"unwind::libunwind::_Unwind_Exception" = type { i64, [0 x i8], void (i32, %"unwind::libunwind::_Unwind_Exception"*)*, [0 x i8], [6 x i64], [0 x i8] }
%"unwind::libunwind::_Unwind_Context" = type {}
@ref.5 = internal unnamed_addr constant [1 x i32] [i32 1], align 4