multithreading - 使用 ref 类形式 c++ 中的线程进行并行工作
问题描述
我目前在 HMI 工作。我必须发送一条消息并等待回复。但是如果我使用 while 循环来等待响应,我的 HMI 会停止交互,等待 while 循环结束。
我尝试使用线程,并尝试在 HMI ref 类中创建一个线程函数来执行包含 while 循环的函数。但我不知道该怎么做。你能帮我解决这个问题,还是给我另一种方法来进行并行工作?谢谢
这是包含另一个类的while循环的代码
bool Robot::waitArrival(char* at)
{
char _status[256];
strcpy(_status, "Going to ");
strcat(_status, static_cast<char*>(at));
do
{
this->handUpdates->lock();
strcpy(this->status, this->handUpdates->getStatus());
this->handUpdates->unlock();
ArUtil::sleep(1000); //1s
} while (strcmp(this->status, _status) == 0);
strcpy(_status, "Arrived at ");
strcat(_status, static_cast<char*>(at));
if (strcmp(this->status, _status) == 0)
return true;
else
return false;
}
这是我的人机界面。通过点击button3我调用Controller ref类中的ctr_main()函数,ctr_main()函数调用waitArrival()函数,
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
Thread t1(&Controleur::ctr_main);
}
解决方案
推荐阅读
- html - 如何将多张桌子变成一张桌子
- ios - lldb Xcode 没有响应 | Fabric .pcm 文件复制
- html - 选择中的 Onchange 属性未在 codeigniter 中触发
- javascript - 从 localhost:xxxx 加载时的内容安全策略 ( style-src )
- javascript - 如何创建包装器组件并传递道具以在包装器的父级中调用它
- python - 无法获取用户信息,出现“unauthorized_client”之类的错误
- javascript - 如何从 tinymce 编辑器实例中获取价值
- javascript - 在饼图上加载自定义弹出点击点击highcharts
- javascript - 硒发布到 Instagram
- jquery - 如何为 JQUERY 数据表返回 JSON 数据?