C ++似乎变量与多线程" flush "
c++ it seems that variable doesn't " flush " with multi thread
is_master_ def:
volatile bool is_master_;
is_master_值被另一个线程设置为 true,但似乎is_master_值 dosnt 刷新(它不会产生致命错误......如果我添加 cout <<"foo"<
void MasterSlaveSynchronize::validateSingleMaster(){
if(is_master_){
cout << "FATAL ERROR HAS OCCURRED BOTH MASTER";
if(!is_leader_master_){
cout << "CHOSE AS VICTIM IN MASTER-MATSER. SET THIS HOST AS SLAVE";
is_master_ = false;
}
}
}
>来电代码:
while(1){
int n = recvfrom(sockId, buf, HEARBEAT_SIZE, 0, (struct sockaddr *) &from,
&length);
if (n < 0) {
REGISTER_ERROR("Failed to recieved hearbeat");
} else {
gettimeofday(&instance_->last_hearbeat_got_, NULL);
instance_->validateSingleMaster();
}
}
您希望我发表评论作为答案:
也许确实如此,但是因为您不使用换行符,因此输出流 不冲洗。
这种行为在这里得到了很好的解释:
为什么 printf 在调用后不会刷新,除非格式字符串中有换行符?
相关文章:
- 在C++中使用cURL和多线程
- 多线程双缓冲区
- 为什么我的多线程作业队列崩溃
- 在main()之外初始化std::vector会导致性能下降(多线程)
- 试图创建一个多线程程序来查找0-100000000之间的总素数
- 为什么一个向量上的多线程操作很慢
- 学习多线程C++:添加线程不会使执行速度更快,即使它看起来应该
- 全局变量 多读取器 一个写入器多线程安全?
- boost::文件系统::recursive_directory_iterator多线程安全
- 如何阻止TensorFlow的多线程
- 如何在多线程中正确使用unique_ptr进行多态性?
- 并发/多线程:是否可以以这种方式生成相同的输出?
- sigwait() 在多线程程序中不起作用
- 多线程程序中出现意外的内存泄漏
- 静态 constexpr 类成员变量对多线程读取是否安全?
- 多线程比没有线程C++慢
- 具有 C++11 多线程的特征库
- 通过安装信号处理程序关闭多线程应用程序
- 成员变量在多线程 C++ 时自行更改
- C ++似乎变量与多线程" flush "