chsvlib
chsv helper source code
chsvthrd\chsv_thread_local_1.cpp

Demonstrates a usage and an effect of the chsv_thread_local macro.

#include <iostream>
#include <string>
#include <thread>
#include <mutex>
#include "chsvthrd.h"
chsv_thread_local(unsigned int, rage) = 1;
std::mutex cout_mutex;
void increase_rage(const std::string& thread_name)
{
++rage;
std::lock_guard<std::mutex> lock(cout_mutex);
std::cout << "Rage counter for " << thread_name << ": " << rage << '\n';
}
int main()
{
std::thread a(increase_rage, "a"), b(increase_rage, "b");
{
std::lock_guard<std::mutex> lock(cout_mutex);
std::cout << "Rage counter for main: " << rage << '\n';
}
a.join();
b.join();
return 0;
}
/*
Output:
=======
Rage counter for a: 2
Rage counter for b: 2
Rage counter for main: 1
*/
#define chsv_thread_local(type, name)
A macro simplifying work with thread-specific storages. It is introduced to implement syntax similar ...
Definition: chsvthrd.h:1565
An interface for the portable implementation of threads as defined in C11 standard supplemented with ...
std::basic_string< char, std::char_traits< char >, ::Chusov::Memory::allocator< char > > string
An instantiation of the standard basic_string class template for handling multi-byte strings allocate...
Definition: chsvstringex.h:126