Skip to content

Instantly share code, notes, and snippets.

@eao197
eao197 / std_multithreading_basics.cpp
Last active April 12, 2024 13:42
Примеры для лекции про базовые средства поддержки многопоточности в C++
/***
Класс std::thread
*/
#include <iostream>
#include <thread>
void SayHello()
@eao197
eao197 / templates_part2.cpp
Last active April 10, 2024 10:03
Примеры для второй части лекции про шаблоны C++
/***
SFINAE: Substitution failure is not an error
*/
// В основном базируется на std::enable_if
// https://en.cppreference.com/w/cpp/types/enable_if
#include <type_traits>
@eao197
eao197 / templates_part1.cpp
Last active April 10, 2024 07:55
Примеры для первой части лекции про шаблоны C++
/***
Реализация шаблона должна быть доступна компилятору.
Поэтому шаблоны размещают в .hpp-файлах
*/
/////////////////////////////////////////////////////
/***
@eao197
eao197 / custom_data_source_message.cpp
Created March 12, 2024 12:17
An example of sending so_5::stats::messages::quantity<int> via custom data-source
#include <so_5/all.hpp>
namespace example
{
class a_stats_listener_t final : public so_5::agent_t
{
public :
a_stats_listener_t( context_t ctx )
: so_5::agent_t( std::move(ctx) )
@eao197
eao197 / same_stop_guard_several_times.cpp
Created March 2, 2024 07:15
A demo of using the same stop_guard several times
#include <so_5/all.hpp>
#include <iostream>
class shutdown_initiated final : public so_5::signal_t {};
class my_stop_guard final : public so_5::stop_guard_t
{
const so_5::mbox_t m_dest;
@eao197
eao197 / sketch.cpp
Created February 9, 2024 09:58
Вольная вариация на тему std::latch, но для ситуации, когда значение счетчика заранее неизвестно.
class meeting_room_t {
std::mutex lock_;
std::condition_variable wakeup_cv_;
unsigned attenders_{};
public:
meeting_room_t() = default;
void enter() {
@eao197
eao197 / isdefault_impl_benchmark.cpp
Created January 19, 2024 07:20
Примитивный бенчмарк для демонстрации скорости работы разных реализаций isDefault
#include <chrono>
#include <iostream>
#include <string>
#include <variant>
namespace isdefault_benchmark
{
class time_meter_t
{
@eao197
eao197 / adv_thread_pool_cooperative.cpp
Created January 11, 2024 05:24
An example of adv_thread_pool with cooperative FIFO
#include <so_5/all.hpp>
struct m1 final : public so_5::signal_t {};
struct m2 final : public so_5::signal_t {};
struct m3 final : public so_5::signal_t {};
struct done final : public so_5::signal_t {};
class A final : public so_5::agent_t
{
public:
@eao197
eao197 / restinio_server_addr_parser.cpp
Created November 28, 2023 10:52
Пример парсинга адреса сервера вида "http://localhost:8088/" имеющимися в RESTinio средствами. С разбором на составляющие: (http|https), (host|ipv6|ipv4) и опциональный порт
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <doctest/doctest.h>
#include <restinio/helpers/http_field_parsers/host.hpp>
namespace example
{
namespace ep = restinio::easy_parser;
@eao197
eao197 / locals.mxx
Created October 6, 2023 07:10
Пример проектных файлов для m++ v3 (эти файлы использовались для компиляции m++v4 посредством m++v3)
if defined( "UNIX" ) && !defined( "GNU" )
define "GNU";
objPath = "o";
if !defined( "NOAUTODEP" ) {
autodepIncludePathList += ".";
autodepIncludePathList += "h";
autodepIncludePathList += "mxx/h";
}