我看到在Visual C ++ 2008中不再支持strerror_r(...)API,可能是因为线程安全性问题。我想在程序中使用类似的功能。还有其他winapi与strerror_r(..)做相同的事情吗?
我正在寻找一个比较器运算符,可用于在C++ 11下原子地比较两个原子变量.在这里,我不想交换存储在这些原子obj下的值,所以我对compare_and_swap函数不感兴趣.请参考以下示例:
std::atomic<uint32_t> readIdx{0};
std::atomic<uint32_t> writeIdx{0};
while(writeIdx + 1 == readIdx) <<<<------------------
{
std::this_thread::yield();
}
Run Code Online (Sandbox Code Playgroud)
我想要的只是用箭头线表示的代码是原子的.可能吗?如果没有,那writeIdx == readIdx是原子操作吗?
我有一个下面提到的C++代码:
#include<iostream>
#include<stdexcept>
const long MAX = 10240000;
class Widget{
public:
Widget(){
ok = new int [1024];
prob = new int [100*MAX];
}
~Widget(){
std::cout<<"\nDtoR of Widget is called\n";
delete ok; ok = NULL;
delete prob; prob = NULL;
}
//keeping below public: Intentionally
int* ok;
int* prob;
};
void func(){
Widget* pw = NULL; // <<<<--------------- Issue in Here
try{
pw = new Widget;
}
catch(...){
delete pw;
std::cout<<"\nIn catch BLOCK\n";
if(pw->ok == NULL){
std::cout<<"\n OK is NULL\n";
} …Run Code Online (Sandbox Code Playgroud)