Skip to content

Instantly share code, notes, and snippets.

@eao197
eao197 / approach1.cpp
Created April 26, 2024 13:08
Возможные реализации thread_pool-ов для задачи рекурсивного обхода подкаталогов
#include <condition_variable>
#include <functional>
#include <iostream>
#include <mutex>
#include <queue>
#include <thread>
#include <vector>
namespace demo
{
@eao197
eao197 / gist:2b48c0adcaa0030b539f982759d1ba38
Created April 12, 2024 04:19
Заметки для лекции про стандартные контейнеры C++
/***
https://en.cppreference.com/w/cpp/container
*/
/***
Задача стандартной библиотеки -- быть стандартной библиотекой.
@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: