Skip to content

Instantly share code, notes, and snippets.

View mtrencseni's full-sized avatar

Marton Trencseni mtrencseni

  • Dubai
View GitHub Profile
@mtrencseni
mtrencseni / bakery.cpp
Created July 7, 2025 03:52
Lamport's Bakery algorithm in C++
#include <atomic>
#include <chrono>
#include <cstdint>
#include <iostream>
#include <thread>
#include <vector>
/*-----------------------------------------------------------
Lamport's bakery algorithm
-----------------------------------------------------------*/
def generate_composite():
composite = {}, {}
return composite
def split(composite):
left = {'value': composite[0]}
right = {'value': composite[1]}
# we enable both left and right parts to peek at each other
# in physics, this is called action-at-a-distance
left['other'] = right
#include <asio.hpp>
#include <iostream>
#include <unordered_map>
#include <vector>
#include <deque>
#include <string>
#include "json.hpp"
using asio::ip::tcp;
using json = nlohmann::json;
#include <iostream>
#include <string>
#include <asio.hpp>
#include <asio/io_context.hpp>
#include <signal.h>
#include "Utils.hpp"
#include "MessageQueue.hpp"
using asio::awaitable;
using asio::co_spawn;
#ifndef __MESSAGEQUEUE_HPP__
#define __MESSAGEQUEUE_HPP__
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <asio.hpp>
#include "Utils.hpp"
#ifndef __UTILS_HPP__
#define __UTILS_HPP__
#include <map>
#include <regex>
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <map>
#include <regex>
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <cctype>
#include <iostream>
#include <string>
#include <asio.hpp>
#include <asio/io_context.hpp>
using asio::awaitable;
using asio::co_spawn;
using asio::detached;
using asio::ip::tcp;
using asio::use_awaitable;
__ __ ___ ___
| \/ | |_ _| | _ )
| |\/| | | | | _ \
|_| |_|ore|___|ncredible|___/ash - V3.3.3 "Bentley Edition - BYG24"
______________________________________________________________________
NOT FOR COMMERCIAL USE - IF YOU BOUGHT THIS YOU GOT RIPPED OFF
Logging_MU1452-MHI2_ER_POG11_P5176-JTB-07403.01.20119200BE:
HW Number: 055 - PN: 9P1035041R
from time import time
from random import random
from statistics import mean, stdev
def coin_flip(bias=0.5):
if random() < bias:
return 1
else:
return 0