以下是我的代码
#include<iostream>
using namespace std;
static pthread_mutex_t testlock;
pthread_t test_thread;
void *test(void*)
{
pthread_mutex_lock(&testlock);
printf("thread Test() \n");
pthread_mutex_unlock(&testlock);
}
int main()
{
pthread_mutex_init(&testlock, NULL);
pthread_mutex_lock(&testlock);
printf("Main lock \n");
pthread_create(&test_thread, NULL, test, NULL);
sleep(1); //更加明显的观察到是否执行了创建线程的互斥锁
printf("Main unlock \n");
pthread_mutex_unlock(&testlock);
sleep(1);
pthread_join(test_thread,NULL);
pthread_mutex_destroy(&testlock);
return 0;
}
g++ 编译完全可以通过
g++ -o thread main.cpp -lpthread -lstdc++
x86的机器上可以跑
然后我开始尝试使用arm的c++编译器,结果拉稀了
root/gcc/gcc-4.4.4-glibc-2.11.1-multilib-1.0/arm-fsl-linux-gnueabi/bin/arm-none-linux-gnueabi-g++ main.cpp -o gfarmcpp -lpthread -lstdc++
main.cpp:4:19: error: iostream: No such file or directory
main.cpp: In function 'int main()':
main.cpp:25: error: 'sleep' was not declared in this scope
|