User Tools

Site Tools


c:c_threads:thread_safe_function

C - C++ Threads - Thread safe function

thread_safe_function.hpp

#pragma once
 
#include <string>
 
void thread_safe_function(std::string str);

thread_safe_function.cpp

#include "thread_safe_function.hpp"
#include <string>
#include <iostream>
#include <mutex>
 
std::mutex mtx;
 
void thread_safe_function(std::string str)
{
  std::lock_guard<std::mutex> lck(mtx);
 
  std::cout << str << std::endl;
}

References

c/c_threads/thread_safe_function.txt · Last modified: 2021/04/28 09:31 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki