Last active
August 29, 2015 14:01
-
-
Save CaptainJH/254e88a7e8ab04e69824 to your computer and use it in GitHub Desktop.
C++ Multithreading
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <thread> | |
#include <mutex> | |
#include <condition_variable> | |
std::mutex g_mut; | |
std::condition_variable g_newMsgCondition; | |
void AddNewDlgMessage(const std::wstring& t) | |
{ | |
std::lock_guard<std::mutex> lk(g_mut); | |
g_msg.push_back(t); | |
g_newMsgCondition.notify_one(); | |
} | |
void UIDlgThread() | |
{ | |
while(true) | |
{ | |
std::unique_lock<std::mutex> lk(g_mut); | |
g_newMsgCondition.wait(lk, []{return !g_msg.empty() || g_procedureFinished;}); | |
if(g_msg.empty() && g_procedureFinished) | |
break; | |
ExtractTextTitleAndBody(g_msg.front(), g_DlgTitle, g_DlgText); | |
g_msg.erase(g_msg.begin()); | |
lk.unlock(); | |
DialogBox(g_hInst, MAKEINTRESOURCE(IDD_MAINDIALOG), NULL, DialogProc); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment