#include <iostream>
#include <thread>
#include <chrono>
#include <string>
#include <mutex>
signed int ii = 0;
std::mutex _mutex;
void f1(void* _msg)
{
std::string _string = std::string((char*)_msg);
while (1) {
_mutex.lock();
std::cout << _string << "f1(" << ++ii << ")" << std::endl;
_mutex.unlock();
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}
}
void f2(void* _msg)
{
std::string _string = std::string((char*)_msg);
while (1) {
_mutex.lock();
std::cout << _string << "f2(" << --ii << ")" << std::endl;
_mutex.unlock();
std::this_thread::sleep_for(std::chrono::seconds(1));
}
}
int main(void)
{
char _string[] = "Hello World";
std::thread _thread1(f1, &_string);
std::thread _thread2(f2, &_string);
_thread1.join();
_thread2.join();
return 0;
}
'Programming > C,C++' 카테고리의 다른 글
ucs2 to utf8 (0) | 2021.03.09 |
---|---|
C++ 11, ucs2 to utf8 (0) | 2020.08.20 |
CRC16 ccitt (0) | 2020.07.13 |
C++ file read binary (0) | 2020.07.12 |
ModX (0) | 2018.04.28 |