用户i/o线程C
User I/O on threads C++
我这里有一些代码,该代码由窗口的类组成(使用NANA C )和一些用于网络的线程。但是,我似乎无法以任何方式向用户输出。我尝试使用消息框,打印到主机上的文本框,但不会出现。这是nana还是boost.thread?
的问题如果这是boost的问题。线程我可以切换到std :: thread,但我不认为它会起作用。
void thread()//Let's say this function is started on a thread and the window is started on main
{
append(L"append test");
MsgBox(L"msgbox test"):
}
有一个NANA演示说明了如何在其他线程中附加文本。
#include <nana/gui.hpp>
#include <nana/gui/widgets/textbox.hpp>
#include <nana/gui/widgets/button.hpp>
#include <mutex>
#include <condition_variable>
#include <thread>
int main()
{
using namespace nana;
form fm(API::make_center(300, 250));
textbox txt(fm, rectangle(10, 10, 280, 190));
button btn(fm, rectangle(10, 220, 200, 20));
btn.caption("append texts in other thread");
std::mutex mutex;
std::condition_variable condvar;
volatile bool running = true;
std::thread thrd([&]
{
while(running)
{
std::unique_lock<std::mutex> lock(mutex);
condvar.wait(lock);
txt.append(L"append a new linen", false);
msgbox mb(L"hello");
mb<<L"This is a demo";
mb.show();
}
});
btn.events().click([&]
{
std::lock_guard<std::mutex> lock(mutex);
condvar.notify_one();
});
fm.events().unload([&]
{
running = false;
std::lock_guard<std::mutex> lock(mutex);
condvar.notify_one();
});
fm.show();
exec();
thrd.join();
}
使用NANA C 库1.0.2创建此演示,在Windows/Linux上正常工作
相关文章:
- 使用 task_group 的英特尔线程构建模块性能不佳(新用户)
- 用于在C++中计算用户数据的线程
- 如何将用户输入从控制台传递到不同线程中的对象 -> QTcpsocket
- 如何将每线程用户数据传递到ASIO处理程序中
- 如何在不让用户等待的情况下管理多个线程
- C++等待用户输入的中断线程
- 用户i/o线程C
- 在用户模式下从另一个进程回调,没有额外的线程
- 根据用户请求停止tbb线程
- 程序基于用户输入创建多个线程不起作用(cin)
- 在多线程程序中通过用户事件传递短数据的正确方法是什么
- std::线程在用户或内核空间中进行管理
- 用户模式计划程序线程的最大数量
- xiAPI:无法更改线程调度程序,请检查实时优先级的用户限制
- Asio内部线程对用户透明吗?
- 选择线程:超时和用户输入
- 多线程使用用户定义的对象
- 如何调度/创建用户级线程,以及如何创建内核级线程
- 用户空间线程库
- 线程安全的用户数据与这个websocket++示例