#include <iostream>
#include <map>
#include <thread>
#define SIZE 1024
#define AMOUNT 100000
#define THREADS 4
class A
{
private:
char a[SIZE];
};
void test()
{
std::cout << "test start\n";
std::map<int, A*> container;
for(int i=0; i<AMOUNT; i++)
{
A* a = new A();
std::pair<int, A*>p = std::make_pair(i, a);
container.insert(p);
}
std::cout << "test release\n";
for(int i=0; i<AMOUNT; i++)
{
auto iter = container.find(i);
delete iter->second;
container.erase(iter);
}
std::cout << "test end\n";
}
int main()
{
std::thread ts[THREADS];
for(int i=0; i<THREADS; i++) …Run Code Online (Sandbox Code Playgroud) 我已经在谷歌上搜索了很长一段时间,我没有看到任何类似的东西,所以这里是。我正在尝试创建一个小的静态链接二进制文件,它可以很容易地分布在我家庭网络上的机器上。这是一个非常小的项目,所以我试图让事情变得简单。
当我在 ARM 32 位架构上静态链接 pthread 库时,我遇到了很大的困难。令人沮丧的是,完全相同的代码在 x86 的所有版本上都可以正常工作。这是我的 test.cpp 程序:
void threader( int num ) {
std::cout << "Child Thread Starting" << std::endl;
try {
throw 20;
} catch (int e) {
std::cout << "Child Thread Success" << std::endl;
}
int x = 0;
do {
x++;
} while (true);
}
int main(int argc, char *argv[]) {
std::cout << "Main Thread Starting" << std::endl;
new std::thread(&threader, 0);
try {
throw 20;
} catch (int e) {
std::cout << "Main …Run Code Online (Sandbox Code Playgroud) 当我std::call_once在 Linux 2.6.36 版中使用时,出现错误:
terminate called after throwing an instance of 'std::system_error'
what(): Unknown error -1
Aborted
Run Code Online (Sandbox Code Playgroud)
编译命令:
mipsel-buildroot-linux-uclibc-g++ callonce.cpp -o callonce -static -lpthread
Run Code Online (Sandbox Code Playgroud)
我的代码:
#include <iostream>
#include <mutex>
using namespace std;
int main()
{
cout << "Hello world" << std::endl;
static once_flag of;
call_once(of,[]{});
return 0;
}
Run Code Online (Sandbox Code Playgroud)