Skip to content

Instantly share code, notes, and snippets.

View chaelim's full-sized avatar

C.S. Lim chaelim

View GitHub Profile
@chaelim
chaelim / InflatableSeqLock.cpp
Created December 13, 2016 22:42 — forked from davedice/InflatableSeqLock.cpp
Inflatable SeqLock
// InflatableSeqLock
// Copyright(C) 2016 Oracle and/or its affiliates
// Dave Dice : https://blogs.oracle.com/dave
//
// Remarks:
// * Implements composite writer mutex and seqlock in a single word-sized lock.
// Allows optimistic reading and pessimistic writing.
// Readers don't write to shared synchronization metadata, which helps avoid
// coherence traffic. Readers must tolerate observing inconsistent state, however.
// * Writer mutex is based on LIFO-CR lock from http://arxiv.org/abs/1511.06035.
// Build: g++ -O3 -std=gnu++14 -m64 MonoTime.cc -lpthread -o MonoTime -mmemory-model=tso
//
// Dave Dice -- blogs.oracle.com/dave
#include <thread>
#include <chrono>
#include <iostream>
#include <vector>
#include <mutex>
#include <random>